diff --git a/dist/Tinlake.d.ts b/dist/Tinlake.d.ts index 9479432..cabe874 100644 --- a/dist/Tinlake.d.ts +++ b/dist/Tinlake.d.ts @@ -64,6 +64,7 @@ interface ethI { contract: (arg0: any) => { at: (arg0: any) => void; }; + abi: any; } export declare type Address = string; export interface Loan { @@ -110,7 +111,7 @@ export declare class Tinlake { /** * @param owner Owner of the new NFT */ - mintNFT: (owner: string, tokenId: string) => Promise; + mintNFT: (owner: string, tokenId: string, ref: string, amount: string, asset: string) => Promise; /** * @param owner Owner of the created loan */ diff --git a/dist/Tinlake.es.js b/dist/Tinlake.es.js index 120f569..a161a5f 100644 --- a/dist/Tinlake.es.js +++ b/dist/Tinlake.es.js @@ -27857,25 +27857,6 @@ var contractAbiNft = [ stateMutability: "nonpayable", type: "function" }, - { - constant: false, - inputs: [ - { - name: "usr", - type: "address" - }, - { - name: "tkn", - type: "uint256" - } - ], - name: "mint", - outputs: [ - ], - payable: false, - stateMutability: "nonpayable", - type: "function" - }, { constant: false, inputs: [ @@ -28017,6 +27998,37 @@ var contractAbiNft = [ stateMutability: "view", type: "function" }, + { + constant: false, + inputs: [ + { + name: "usr", + type: "address" + }, + { + name: "tkn", + type: "uint256" + }, + { + name: "ref", + type: "string" + }, + { + name: "amount", + type: "uint256" + }, + { + name: "asset", + type: "string" + } + ], + name: "mint", + outputs: [ + ], + payable: false, + stateMutability: "nonpayable", + type: "function" + }, { constant: true, inputs: [ @@ -28040,6 +28052,37 @@ var contractAbiNft = [ stateMutability: "view", type: "function" }, + { + constant: true, + inputs: [ + { + name: "", + type: "uint256" + } + ], + name: "data", + outputs: [ + { + name: "reference_id", + type: "string" + }, + { + name: "amount", + type: "uint256" + }, + { + name: "asset_type", + type: "string" + }, + { + name: "borrower", + type: "address" + } + ], + payable: false, + stateMutability: "view", + type: "function" + }, { inputs: [ ], @@ -34723,15 +34766,14 @@ var Tinlake = /** @class */ (function () { /** * @param owner Owner of the new NFT */ - this.mintNFT = function (owner, tokenId) { return __awaiter(_this, void 0, void 0, function () { - var tkn, txHash; + this.mintNFT = function (owner, tokenId, ref, amount, asset) { return __awaiter(_this, void 0, void 0, function () { + var txHash; return __generator(this, function (_a) { switch (_a.label) { - case 0: - tkn = abiCoder$1.encodeParameter('uint', tokenId); - return [4 /*yield*/, this.contracts.nft.mint(owner, tkn, this.ethConfig)]; + case 0: return [4 /*yield*/, executeAndRetry(this.contracts.nft.mint, [owner, tokenId, ref, amount, asset, this.ethConfig])]; case 1: txHash = _a.sent(); + console.log("[NFT.mint] txHash: " + txHash); return [2 /*return*/, waitAndReturnEvents(this.eth, txHash, this.contracts['nft'].abi, this.transactionTimeout)]; } }); @@ -35017,7 +35059,7 @@ function executeAndRetry(f, args) { return [2 /*return*/, result]; case 2: e_1 = _a.sent(); - // using error message, since error code -32603 is not unique enough + // using error message, since error code -32603 is not unique enough // todo introduce retry limit if (e_1 && e_1.message && (e_1.message.indexOf("Cannot read property 'number' of null") !== -1 || e_1.message.indexOf('error with payload') !== -1)) { diff --git a/dist/Tinlake.js b/dist/Tinlake.js index a0670ed..2fe313b 100644 --- a/dist/Tinlake.js +++ b/dist/Tinlake.js @@ -27863,25 +27863,6 @@ var contractAbiNft = [ stateMutability: "nonpayable", type: "function" }, - { - constant: false, - inputs: [ - { - name: "usr", - type: "address" - }, - { - name: "tkn", - type: "uint256" - } - ], - name: "mint", - outputs: [ - ], - payable: false, - stateMutability: "nonpayable", - type: "function" - }, { constant: false, inputs: [ @@ -28023,6 +28004,37 @@ var contractAbiNft = [ stateMutability: "view", type: "function" }, + { + constant: false, + inputs: [ + { + name: "usr", + type: "address" + }, + { + name: "tkn", + type: "uint256" + }, + { + name: "ref", + type: "string" + }, + { + name: "amount", + type: "uint256" + }, + { + name: "asset", + type: "string" + } + ], + name: "mint", + outputs: [ + ], + payable: false, + stateMutability: "nonpayable", + type: "function" + }, { constant: true, inputs: [ @@ -28046,6 +28058,37 @@ var contractAbiNft = [ stateMutability: "view", type: "function" }, + { + constant: true, + inputs: [ + { + name: "", + type: "uint256" + } + ], + name: "data", + outputs: [ + { + name: "reference_id", + type: "string" + }, + { + name: "amount", + type: "uint256" + }, + { + name: "asset_type", + type: "string" + }, + { + name: "borrower", + type: "address" + } + ], + payable: false, + stateMutability: "view", + type: "function" + }, { inputs: [ ], @@ -34729,15 +34772,14 @@ var Tinlake = /** @class */ (function () { /** * @param owner Owner of the new NFT */ - this.mintNFT = function (owner, tokenId) { return __awaiter(_this, void 0, void 0, function () { - var tkn, txHash; + this.mintNFT = function (owner, tokenId, ref, amount, asset) { return __awaiter(_this, void 0, void 0, function () { + var txHash; return __generator(this, function (_a) { switch (_a.label) { - case 0: - tkn = abiCoder$1.encodeParameter('uint', tokenId); - return [4 /*yield*/, this.contracts.nft.mint(owner, tkn, this.ethConfig)]; + case 0: return [4 /*yield*/, executeAndRetry(this.contracts.nft.mint, [owner, tokenId, ref, amount, asset, this.ethConfig])]; case 1: txHash = _a.sent(); + console.log("[NFT.mint] txHash: " + txHash); return [2 /*return*/, waitAndReturnEvents(this.eth, txHash, this.contracts['nft'].abi, this.transactionTimeout)]; } }); @@ -35023,7 +35065,7 @@ function executeAndRetry(f, args) { return [2 /*return*/, result]; case 2: e_1 = _a.sent(); - // using error message, since error code -32603 is not unique enough + // using error message, since error code -32603 is not unique enough // todo introduce retry limit if (e_1 && e_1.message && (e_1.message.indexOf("Cannot read property 'number' of null") !== -1 || e_1.message.indexOf('error with payload') !== -1)) { diff --git a/rollup.config.js b/rollup.config.js index 078a258..f9003c3 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -19,10 +19,10 @@ export default { ], external: [ // ...Object.keys(pkg.dependencies || {}), - ...Object.keys(pkg.peerDependencies || {}), + ...Object.keys(pkg.peerDependencies || {}) ], plugins: [ - resolve(), + resolve({preferBuiltins: true}), commonjs(), json({ // All JSON files will be parsed by default, diff --git a/src/Tinlake.ts b/src/Tinlake.ts index 68d020b..9d27f8a 100644 --- a/src/Tinlake.ts +++ b/src/Tinlake.ts @@ -4,6 +4,7 @@ const abiCoder = new AbiCoder(); import BN from 'bn.js'; import { sha3 } from 'web3-utils'; + import contractAbiNft from './abi/test/SimpleNFT.abi.json'; import contractAbiTitle from './abi/Title.abi.json'; import contractAbiCurrency from './abi/test/SimpleToken.abi.json'; @@ -91,6 +92,7 @@ interface ethI { getTransactionReceipt: (arg0: any, arg1: (err: any, receipt: any) => void) => void; getTransactionByHash: (arg0: any, arg1: (err: any, tx: any) => void) => void; contract: (arg0: any) => { at: (arg0: any) => void }; + abi: any; } interface Events { @@ -269,25 +271,26 @@ export class Tinlake { /** * @param owner Owner of the new NFT */ - mintNFT = async (owner: string, tokenId: string) => { - const tkn = abiCoder.encodeParameter('uint', tokenId) - const txHash = await this.contracts.nft.mint(owner, tkn, this.ethConfig); + mintNFT = async (owner: string, tokenId: string, ref: string, amount: string, asset:string) => { + const txHash = await executeAndRetry(this.contracts.nft.mint, [owner, tokenId, ref, amount, asset, this.ethConfig]); + console.log(`[NFT.mint] txHash: ${txHash}`); return waitAndReturnEvents(this.eth, txHash, this.contracts['nft'].abi, this.transactionTimeout); - } + }; + /** * @param owner Owner of the created loan */ adminAdmit = async (registry: string, nft: string, principal: string, owner: string) => { const txHash = await executeAndRetry(this.contracts.admit.admit, [registry, nft, principal, owner, this.ethConfig]) console.log(`[Admit.admit] txHash: ${txHash}`); - return waitAndReturnEvents(this.eth, txHash, this.contracts['nft'].abi, this.transactionTimeout); + return waitAndReturnEvents(this.eth, txHash, this.contracts['nft'].abi, this.transactionTimeout); } adminAppraise = async (loanID: string, appraisal: string) => { const txHash = await executeAndRetry(this.contracts.appraiser.file, [loanID, appraisal, this.ethConfig]); console.log(`[Appraisal.file] txHash: ${txHash}`); return waitAndReturnEvents(this.eth, txHash, this.contracts['nft'].abi, this.transactionTimeout); - + } getAppraisal = async (loanID: string) => { @@ -308,8 +311,8 @@ export class Tinlake { * @param wad Amount which should be repaid * @param usr Address that receives the NFT */ - repay = async (loanId: string, wad: string, usr: string)=> { - const txHash = await executeAndRetry(this.contracts.reception.repay, [loanId, wad, usr, this.ethConfig]) + repay = async (loanId: string, wad: string, usr: string) => { + const txHash = await executeAndRetry(this.contracts.reception.repay, [loanId, wad, usr, this.ethConfig]) console.log(`[Reception.repay] txHash: ${txHash}`); return waitAndReturnEvents(this.eth, txHash, this.contracts['reception'].abi, this.transactionTimeout); } @@ -365,8 +368,7 @@ export class Tinlake { * using initFee * @param owner Owner of the created loan */ - whitelist = async (registry: Address, nft: string, principal: string, appraisal: string, - fee: string, owner: string) => { + whitelist = async (registry: Address, nft: string, principal: string, appraisal: string, fee: string, owner: string) => { const txHash = await executeAndRetry(this.contracts.admin.whitelist, [registry, nft, principal, appraisal, fee, owner, this.ethConfig]); console.log(`[Admin.whitelist] txHash: ${txHash}`); return waitAndReturnEvents(this.eth, txHash, this.contracts['nft'].abi, this.transactionTimeout); @@ -404,7 +406,7 @@ async function executeAndRetry (f: Function, args: Array = []) : Promise