@verified-network/verified-sdk
Version:
An SDK to develop applications on the Verified Network
136 lines (135 loc) • 6.93 kB
JavaScript
"use strict";
// SPDX-License-Identifier: BUSL-1.1
// @ts-nocheck
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("../index");
const Vault_json_1 = require("../../abi/custody/Vault.json");
var FUNCTIONS;
(function (FUNCTIONS) {
FUNCTIONS["CREATEVAULT"] = "createVault";
FUNCTIONS["RESETPIN"] = "resetPin";
FUNCTIONS["GETVAULTS"] = "getVaults";
FUNCTIONS["TRANSFERVAULT"] = "transferVault";
FUNCTIONS["GETCREATOR"] = "getCreator";
FUNCTIONS["ADDPARTICIPANT"] = "addParticipant";
FUNCTIONS["REMOVEPARTICIPANT"] = "removeParticipant";
FUNCTIONS["CONFIRMPARTICIPANT"] = "confirmParticipant";
FUNCTIONS["DEFINEQUORUM"] = "defineQuorum";
FUNCTIONS["GETQUORUM"] = "getQuorum";
FUNCTIONS["PROMPTSIGNATURES"] = "promptSignatures";
FUNCTIONS["SIGNTRANSACTION"] = "signTransaction";
FUNCTIONS["CHECKQUORUM"] = "checkQuorum";
FUNCTIONS["GETSHARDS"] = "getShards";
FUNCTIONS["NEWPARTICIPANT"] = "NewParticipant";
FUNCTIONS["NEWTRANSACTION"] = "NewTransaction";
FUNCTIONS["SIGNATURE"] = "SignTransaction";
FUNCTIONS["SNAPSHOT"] = "snapshotBalance";
FUNCTIONS["CALCULATEAVERAGEBALANCE"] = "calculateAverageBalance";
FUNCTIONS["COLLECTCUSTODYFEE"] = "collectCustodyFee";
FUNCTIONS["SETDISTRIBUTOR"] = "setDistributor";
FUNCTIONS["SETCUSTODYFEE"] = "setCustodyFee";
})(FUNCTIONS || (FUNCTIONS = {}));
class Custody extends index_1.VerifiedContract {
constructor(signer, contractNetworkAddress) {
const address = contractNetworkAddress;
super(address, JSON.stringify(Vault_json_1.abi), signer);
this.contractAddress = address;
}
async _getMeeQuote(paymentTokenAddress, functionName, args, apiKey, rpcUrl, isReactNative) {
return await this.getQuote(paymentTokenAddress, functionName, args, rpcUrl, apiKey, isReactNative);
}
async createVault(_creator, options) {
await this.validateInput(index_1.DATATYPES.BYTE32, _creator);
return this.callContract(FUNCTIONS.CREATEVAULT, _creator, options);
}
async getVaults() {
return this.callContract(FUNCTIONS.GETVAULTS);
}
async transferVault(_creator, _transferee, options) {
await this.validateInput(index_1.DATATYPES.BYTE32, _creator);
await this.validateInput(index_1.DATATYPES.ADDRESS, _transferee);
return this.callContract(FUNCTIONS.TRANSFERVAULT, _creator, _transferee, options);
}
async addParticipant(_creator, _participant, _shard, options) {
await this.validateInput(index_1.DATATYPES.BYTE32, _creator);
await this.validateInput(index_1.DATATYPES.BYTE32, _participant);
await this.validateInput(index_1.DATATYPES.STRING, _shard);
return this.callContract(FUNCTIONS.ADDPARTICIPANT, _creator, _participant, _shard, options);
}
async removeParticipant(_creator, _participant, options) {
await this.validateInput(index_1.DATATYPES.BYTE32, _creator);
await this.validateInput(index_1.DATATYPES.BYTE32, _participant);
return this.callContract(FUNCTIONS.REMOVEPARTICIPANT, _creator, _participant, options);
}
async confirmParticipant(_creator, _participant, _confirmation, options) {
await this.validateInput(index_1.DATATYPES.BYTE32, _creator);
await this.validateInput(index_1.DATATYPES.BYTE32, _participant);
await this.validateInput(index_1.DATATYPES.BOOLEAN, _confirmation);
return this.callContract(FUNCTIONS.CONFIRMPARTICIPANT, _creator, _participant, _confirmation, options);
}
async defineQuorum(_creator, _minParticipants, options) {
await this.validateInput(index_1.DATATYPES.BYTE32, _creator);
await this.validateInput(index_1.DATATYPES.NUMBER, _minParticipants);
return this.callContract(FUNCTIONS.DEFINEQUORUM, _creator, _minParticipants, options);
}
async getQuorum(_creator, options) {
await this.validateInput(index_1.DATATYPES.BYTE32, _creator);
return this.callContract(FUNCTIONS.GETQUORUM, _creator, options);
}
async promptSignatures(_creator, options) {
await this.validateInput(index_1.DATATYPES.BYTE32, _creator);
return this.callContract(FUNCTIONS.PROMPTSIGNATURES, _creator, options);
}
async signTransaction(_creator, _participant, _tx, options) {
await this.validateInput(index_1.DATATYPES.BYTE32, _creator);
await this.validateInput(index_1.DATATYPES.BYTE32, _participant);
await this.validateInput(index_1.DATATYPES.STRING, _tx);
return this.callContract(FUNCTIONS.SIGNTRANSACTION, _creator, _participant, _tx, options);
}
async checkQuorum(_creator, _txid, options) {
await this.validateInput(index_1.DATATYPES.BYTE32, _creator);
await this.validateInput(index_1.DATATYPES.STRING, _txid);
return this.callContract(FUNCTIONS.CHECKQUORUM, _creator, _txid, options);
}
async getShards(_creator, _txid, options) {
await this.validateInput(index_1.DATATYPES.BYTE32, _creator);
await this.validateInput(index_1.DATATYPES.STRING, _txid);
return this.callContract(FUNCTIONS.GETSHARDS, _creator, _txid, options);
}
async getCreator(_creator, options) {
await this.validateInput(index_1.DATATYPES.BYTE32, _creator);
return this.callContract(FUNCTIONS.GETCREATOR, _creator, options);
}
async snapshotBalance(_creator, _token, options) {
await this.validateInput(index_1.DATATYPES.BYTE32, _creator);
await this.validateInput(index_1.DATATYPES.ADDRESS, _token);
return this.callContract(FUNCTIONS.SNAPSHOT, _creator, _token, options);
}
async calculateAverageBalance(_creator, _token, options) {
await this.validateInput(index_1.DATATYPES.BYTE32, _creator);
await this.validateInput(index_1.DATATYPES.ADDRESS, _token);
return this.callContract(FUNCTIONS.CALCULATEAVERAGEBALANCE, _creator, _token, _fromTime, _toTime, options);
}
async collectCustodyFee(_token, options) {
await this.validateInput(index_1.DATATYPES.ADDRESS, _token);
return this.callContract(FUNCTIONS.COLLECTCUSTODYFEE, _token, options);
}
async setDistributor(_nominee, options) {
await this.validateInput(index_1.DATATYPES.ADDRESS, _nominee);
return this.callContract(FUNCTIONS.SETDISTRIBUTOR, _nominee, options);
}
async setCustodyFee(_fee, options) {
await this.validateInput(index_1.DATATYPES.NUMBER, _fee);
return this.callContract(FUNCTIONS.SETCUSTODYFEE, _fee, options);
}
notifyNewParticipant(callback) {
this.getEvent(FUNCTIONS.NEWPARTICIPANT, callback);
}
notifyNewTransaction(callback) {
this.getEvent(FUNCTIONS.NEWTRANSACTION, callback);
}
notifySignTransaction(callback) {
this.getEvent(FUNCTIONS.SIGNATURE, callback);
}
}
exports.default = Custody;