implement allowance in plasma and pos
ADD
examples/plasma/erc20/get_allowance.js
+const { plasma } = require('../../config');
+const { getPlasmaClient, from } = require('../../utils');
+
+const execute = async () => {
+ const client = await getPlasmaClient();
+ const erc720Token = client.erc20(plasma.parent.erc20, true);
+
+ const result = await erc720Token.getAllowance(from);
+
+ console.log("result", result);
+
+}
+execute().then(() => {
+}).catch(err => {
+ console.error("err", err);
+}).finally(_ => {
+ process.exit(0);
+})
\ No newline at end of file

ADD
examples/pos/erc20/get_allowance.js
+const { pos } = require('../../config');
+const { getPOSClient, from } = require('../../utils');
+
+const execute = async () => {
+ const client = await getPOSClient();
+ const erc720Token = client.erc20(pos.parent.erc20, true);
+
+ const result = await erc720Token.getAllowance(from);
+
+ console.log("result", result);
+
+}
+execute().then(() => {
+}).catch(err => {
+ console.error("err", err);
+}).finally(_ => {
+ process.exit(0);
+})
\ No newline at end of file

MODIFY
src/plasma/erc20.ts
src/plasma/erc20.ts
@@ -37,6 +37,27 @@ export class ERC20 extends PlasmaToken {
});
}
+ /**
+ * get allowance for user
+ *
+ * @param {string} userAddress
+ * @param {ITransactionOption} [option]
+ * @returns
+ * @memberof ERC20
+ */
+ getAllowance(userAddress: string, option?: ITransactionOption) {
+ this.checkForRoot_("getAllowance");
+
+ return this.getContract().then(contract => {
+ const method = contract.method(
+ "allowance",
+ userAddress,
+ this.contracts_.depositManager.address,
+ );
+ return this.processRead<string>(method, option);
+ });
+ }
+
approve(amount: TYPE_AMOUNT, option: ITransactionOption = {}) {
this.checkForRoot_("approve");
return this.getContract().then(contract => {

MODIFY
src/pos/erc20.ts
src/pos/erc20.ts
@@ -34,6 +34,28 @@ export class ERC20 extends POSToken {
});
}
+ /**
+ * get allowance of user
+ *
+ * @param {string} userAddress
+ * @param {ITransactionOption} [option]
+ * @returns
+ * @memberof ERC20
+ */
+ getAllowance(userAddress: string, option?: ITransactionOption) {
+ this.checkForRoot_("getAllowance");
+
+ return Promise.all([this.getPredicateAddress(), this.getContract()]).then(result => {
+ const [predicateAddress, contract] = result;
+ const method = contract.method(
+ "allowance",
+ userAddress,
+ predicateAddress,
+ );
+ return this.processRead<string>(method, option);
+ });
+ }
+
approve(amount: TYPE_AMOUNT, option?: ITransactionOption) {
this.checkForRoot_("approve");

implement allowance in plasma and pos