@0xcert/ethereum-sandbox
Version:
Test server for local running testing of modules on the Ethereum blockchain.
339 lines • 14.9 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Protocol = void 0;
const contracts = require("../config/contracts");
const deploy_1 = require("../lib/deploy");
class Protocol {
constructor(web3) {
this.web3 = web3;
}
static deploy(web3, from) {
return new Protocol(web3).deploy(from);
}
deploy(from) {
return __awaiter(this, void 0, void 0, function* () {
if (!from) {
from = yield this.web3.eth.getAccounts().then((a) => a[0]);
}
this.erc20 = yield this.deployErc20(from);
this.erc721Enumerable = yield this.deployErc721Enumerable(from);
this.erc721Metadata = yield this.deployErc721Metadata(from);
this.erc721 = yield this.deployErc721(from);
this.xcertDestroyable = yield this.deployXcertDestroyable(from);
this.xcertMutable = yield this.deployXcertMutable(from);
this.xcertPausable = yield this.deployXcertPausable(from);
this.xcertRevokable = yield this.deployXcertRevokable(from);
this.xcert = yield this.deployXcert(from);
this.xcertCreateProxy = yield this.deployXcertCreateProxy(from);
this.xcertUpdateProxy = yield this.deployXcertUpdateProxy(from);
this.xcertBurnProxy = yield this.deployXcertBurnProxy(from);
this.tokenTransferProxy = yield this.deployTokenTransferProxy(from);
this.nftokenTransferProxy = yield this.deployNFTokenTransferProxy(from);
this.nftokenSafeTransferProxy = yield this.deployNFTokenSafeTransferProxy(from);
this.abilitableManageProxy = yield this.deployAbilitableManageProxy(from);
this.nftokenReceiver = yield this.deployNFTokenReceiver(from);
this.xcertDeployProxy = yield this.deployXcertDeployProxy(from);
this.tokenDeployProxy = yield this.deployTokenDeployProxy(from);
this.actionsGateway = yield this.deployActionsGateway(from);
this.xcertDeployGateway = yield this.deployXcertDeployGateway(from);
this.tokenDeployGateway = yield this.deployTokenDeployGateway(from);
this.dappToken = yield this.deployDappToken(from);
return this;
});
}
deployErc20(from) {
return __awaiter(this, void 0, void 0, function* () {
return deploy_1.deploy({
web3: this.web3,
abi: contracts.erc20.abi,
bytecode: contracts.erc20.bytecode,
args: ['ERC20', 'ERC20', 18, '500000000000000000000000000'],
from,
});
});
}
deployErc721Enumerable(from) {
return __awaiter(this, void 0, void 0, function* () {
return deploy_1.deploy({
web3: this.web3,
abi: contracts.erc721Enumerable.abi,
bytecode: contracts.erc721Enumerable.bytecode,
from,
});
});
}
deployErc721Metadata(from) {
return __awaiter(this, void 0, void 0, function* () {
return deploy_1.deploy({
web3: this.web3,
abi: contracts.erc721Metadata.abi,
bytecode: contracts.erc721Metadata.bytecode,
args: ['ERC721 Metadata', 'ERC721Metadata', 'https://0xcert.org/', '.json'],
from,
});
});
}
deployErc721(from) {
return __awaiter(this, void 0, void 0, function* () {
return deploy_1.deploy({
web3: this.web3,
abi: contracts.erc721.abi,
bytecode: contracts.erc721.bytecode,
from,
});
});
}
deployXcertDestroyable(from) {
return __awaiter(this, void 0, void 0, function* () {
const xcert = yield deploy_1.deploy({
web3: this.web3,
abi: contracts.xcert.abi,
bytecode: contracts.xcert.bytecode,
args: ['Destroyable Xcert', 'DestroyableXcert', 'https://0xcert.org/', '.json', '0x1', ['0x9d118770']],
from,
});
return xcert;
});
}
deployXcertMutable(from) {
return __awaiter(this, void 0, void 0, function* () {
const xcert = yield deploy_1.deploy({
web3: this.web3,
abi: contracts.xcert.abi,
bytecode: contracts.xcert.bytecode,
args: ['Mutable Xcert', 'MutableXcert', 'https://0xcert.org/', '.json', '0x2', ['0x0d04c3b8']],
from,
});
return xcert;
});
}
deployXcertPausable(from) {
return __awaiter(this, void 0, void 0, function* () {
const xcert = yield deploy_1.deploy({
web3: this.web3,
abi: contracts.xcert.abi,
bytecode: contracts.xcert.bytecode,
args: ['Pausable Xcert', 'PausableXcert', 'https://0xcert.org/', '.json', '0x3', ['0xbedb86fb']],
from,
});
return xcert;
});
}
deployXcertRevokable(from) {
return __awaiter(this, void 0, void 0, function* () {
const xcert = yield deploy_1.deploy({
web3: this.web3,
abi: contracts.xcert.abi,
bytecode: contracts.xcert.bytecode,
args: ['Revokable Xcert', 'RevokableXcert', 'https://0xcert.org/', '.json', '0x4', ['0x20c5429b']],
from,
});
return xcert;
});
}
deployXcert(from) {
return __awaiter(this, void 0, void 0, function* () {
const xcert = yield deploy_1.deploy({
web3: this.web3,
abi: contracts.xcert.abi,
bytecode: contracts.xcert.bytecode,
args: ['Xcert', 'Xcert', 'https://0xcert.org/', '.json', '0x5', []],
from,
});
return xcert;
});
}
deployXcertCreateProxy(from) {
return __awaiter(this, void 0, void 0, function* () {
return deploy_1.deploy({
web3: this.web3,
abi: contracts.xcertCreateProxy.abi,
bytecode: contracts.xcertCreateProxy.bytecode,
from,
});
});
}
deployXcertUpdateProxy(from) {
return __awaiter(this, void 0, void 0, function* () {
return deploy_1.deploy({
web3: this.web3,
abi: contracts.xcertUpdateProxy.abi,
bytecode: contracts.xcertUpdateProxy.bytecode,
from,
});
});
}
deployXcertBurnProxy(from) {
return __awaiter(this, void 0, void 0, function* () {
return deploy_1.deploy({
web3: this.web3,
abi: contracts.xcertBurnProxy.abi,
bytecode: contracts.xcertBurnProxy.bytecode,
from,
});
});
}
deployTokenTransferProxy(from) {
return __awaiter(this, void 0, void 0, function* () {
return deploy_1.deploy({
web3: this.web3,
abi: contracts.tokenTransferProxy.abi,
bytecode: contracts.tokenTransferProxy.bytecode,
from,
});
});
}
deployNFTokenTransferProxy(from) {
return __awaiter(this, void 0, void 0, function* () {
return deploy_1.deploy({
web3: this.web3,
abi: contracts.nftokenTransferProxy.abi,
bytecode: contracts.nftokenTransferProxy.bytecode,
from,
});
});
}
deployNFTokenSafeTransferProxy(from) {
return __awaiter(this, void 0, void 0, function* () {
return deploy_1.deploy({
web3: this.web3,
abi: contracts.nftokenSafeTransferProxy.abi,
bytecode: contracts.nftokenSafeTransferProxy.bytecode,
from,
});
});
}
deployAbilitableManageProxy(from) {
return __awaiter(this, void 0, void 0, function* () {
return deploy_1.deploy({
web3: this.web3,
abi: contracts.abilitableManageProxy.abi,
bytecode: contracts.abilitableManageProxy.bytecode,
from,
});
});
}
deployXcertDeployProxy(from) {
return __awaiter(this, void 0, void 0, function* () {
return deploy_1.deploy({
web3: this.web3,
abi: contracts.xcertDeployProxy.abi,
bytecode: contracts.xcertDeployProxy.bytecode,
from,
});
});
}
deployTokenDeployProxy(from) {
return __awaiter(this, void 0, void 0, function* () {
return deploy_1.deploy({
web3: this.web3,
abi: contracts.tokenDeployProxy.abi,
bytecode: contracts.tokenDeployProxy.bytecode,
from,
});
});
}
deployNFTokenReceiver(from) {
return __awaiter(this, void 0, void 0, function* () {
return deploy_1.deploy({
web3: this.web3,
abi: contracts.erc721receiver.abi,
bytecode: contracts.erc721receiver.bytecode,
from,
});
});
}
deployActionsGateway(from) {
return __awaiter(this, void 0, void 0, function* () {
const actionsGateway = yield deploy_1.deploy({
web3: this.web3,
abi: contracts.actionsGateway.abi,
bytecode: contracts.actionsGateway.bytecode,
from,
});
yield actionsGateway.instance.methods.grantAbilities(from, 16).send({ from });
yield actionsGateway.instance.methods.addProxy(this.xcertCreateProxy.receipt._address, 0).send({ from });
yield actionsGateway.instance.methods.addProxy(this.tokenTransferProxy.receipt._address, 1).send({ from });
yield actionsGateway.instance.methods.addProxy(this.nftokenTransferProxy.receipt._address, 1).send({ from });
yield actionsGateway.instance.methods.addProxy(this.nftokenSafeTransferProxy.receipt._address, 1).send({ from });
yield actionsGateway.instance.methods.addProxy(this.xcertUpdateProxy.receipt._address, 2).send({ from });
yield actionsGateway.instance.methods.addProxy(this.abilitableManageProxy.receipt._address, 3).send({ from });
yield actionsGateway.instance.methods.addProxy(this.xcertBurnProxy.receipt._address, 4).send({ from });
yield this.tokenTransferProxy.instance.methods.grantAbilities(actionsGateway.receipt._address, 16).send({ from });
yield this.nftokenTransferProxy.instance.methods.grantAbilities(actionsGateway.receipt._address, 16).send({ from });
yield this.xcertCreateProxy.instance.methods.grantAbilities(actionsGateway.receipt._address, 16).send({ from });
yield this.nftokenSafeTransferProxy.instance.methods.grantAbilities(actionsGateway.receipt._address, 16).send({ from });
yield this.xcertUpdateProxy.instance.methods.grantAbilities(actionsGateway.receipt._address, 16).send({ from });
yield this.xcertBurnProxy.instance.methods.grantAbilities(actionsGateway.receipt._address, 16).send({ from });
yield this.abilitableManageProxy.instance.methods.grantAbilities(actionsGateway.receipt._address, 16).send({ from });
return actionsGateway;
});
}
deployXcertDeployGateway(from) {
return __awaiter(this, void 0, void 0, function* () {
const xcertDeployGateway = yield deploy_1.deploy({
web3: this.web3,
abi: contracts.xcertDeployGateway.abi,
bytecode: contracts.xcertDeployGateway.bytecode,
args: [
this.xcertDeployProxy.receipt._address,
this.tokenTransferProxy.receipt._address,
this.xcertCreateProxy.receipt._address,
this.xcertUpdateProxy.receipt._address,
this.abilitableManageProxy.receipt._address,
this.nftokenSafeTransferProxy.receipt._address,
this.xcertBurnProxy.receipt._address,
],
from,
});
yield this.tokenTransferProxy.instance.methods.grantAbilities(xcertDeployGateway.receipt._address, 16).send({ from });
return xcertDeployGateway;
});
}
deployTokenDeployGateway(from) {
return __awaiter(this, void 0, void 0, function* () {
const tokenDeployGateway = yield deploy_1.deploy({
web3: this.web3,
abi: contracts.tokenDeployGateway.abi,
bytecode: contracts.tokenDeployGateway.bytecode,
args: [
this.tokenDeployProxy.receipt._address,
this.tokenTransferProxy.receipt._address,
],
from,
});
yield this.tokenTransferProxy.instance.methods.grantAbilities(tokenDeployGateway.receipt._address, 16).send({ from });
return tokenDeployGateway;
});
}
deployDappToken(from) {
return __awaiter(this, void 0, void 0, function* () {
const dappToken = yield deploy_1.deploy({
web3: this.web3,
abi: contracts.dappToken.abi,
bytecode: contracts.dappToken.bytecode,
args: [
'Dapp token',
'DXC',
18,
this.erc20.receipt._address,
this.tokenTransferProxy.receipt._address,
],
from,
});
yield this.erc20.instance.methods.approve(dappToken.receipt._address, '5000000000000000000000000000').send({ from });
return dappToken;
});
}
}
exports.Protocol = Protocol;
//# sourceMappingURL=protocol.js.map