From 317a8b348bfdf5a5a2b9d3cb43e0c2bc5629cbe8 Mon Sep 17 00:00:00 2001 From: kiki Date: Tue, 4 Jul 2023 10:45:10 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BC=98=E5=8C=96=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.vue | 47 +++- utils/web3x/ippt-abi.json | 41 +++ utils/web3x/usdt-abi.json | 548 +++++++++++++++++++++++++++----------- 3 files changed, 472 insertions(+), 164 deletions(-) diff --git a/pages/index/index.vue b/pages/index/index.vue index 94cba39..0387eec 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -57,6 +57,9 @@ import { web3x } from "@/utils/web3x/web3x.js" + + const ipptAddress = '0x622d7b79a904e00e5fcab06396ff009e441f0186' + export default { components: { GeneralButton, @@ -114,13 +117,45 @@ }) // 当前钱包地址 console.log("当前钱包地址", web3x.selectedAddress); + // 检查 USDT 授权给 IPPT 的数量 + const allowance = await web3x.usdt.$allowance(web3x.selectedAddress, ipptAddress) + + // 如果 allowance 大于某个值则不需要重新授权. 示例为 1000000 USDT + if (allowance > Number(1000000) * 10 ** Number(18)) { + web3x.ippt.$creatCode(this.form.supAddress, web3x.selectedAddress) + uni.hideLoading() + } else { + // 否则则需要重新授权为 0, 然后在进行极限授权 + // 提示最小需授权 XXX USDT, 请取消授权后重新授权 + + // 取消授权 + web3x.usdt.$approve(ipptAddress, 0) + .on("receipt", () => { + console.log("取消授权完成") + // 然后在进行极限授权 + web3x.usdt.approveMAX(ipptAddress) + .on("transactionHash", () => { + console.log("调用极限授权") + + // 调用IPPT 合约绑定上级关系 + // 0xFb4FC7Ddb8c4aa6b944703CE1e89D2B9Aa67a400: 上级地址 + // web3x.selectedAddress: 当前钱包地址 + web3x.ippt.$creatCode(this.form.supAddress, web3x.selectedAddress) + uni.hideLoading() + }) + }) + } + // 授权当前钱包的 USDT 给 IPPT (参数为 IPPT 合约地址) - await web3x.usdt.approveMAX("0x622d7b79a904e00e5fcab06396ff009e441f0186") - uni.hideLoading() - // 调用IPPT 合约绑定上级关系 - // 0xFb4FC7Ddb8c4aa6b944703CE1e89D2B9Aa67a400: 上级地址 - // web3x.selectedAddress: 当前钱包地址 - await web3x.ippt.$creatCode(this.form.supAddress, web3x.selectedAddress) + // web3x.usdt.approveMAX("0x622d7b79a904e00e5fcab06396ff009e441f0186") + // .on("transactionHash", async (receipt) => { + // console.log("transactionHash", receipt) + // // 调用IPPT 合约绑定上级关系 + // // 0xFb4FC7Ddb8c4aa6b944703CE1e89D2B9Aa67a400: 上级地址 + // // web3x.selectedAddress: 当前钱包地址 + // await web3x.ippt.$creatCode(this.form.supAddress, web3x.selectedAddress) + // uni.hideLoading() + // }) }) }, go(val) { diff --git a/utils/web3x/ippt-abi.json b/utils/web3x/ippt-abi.json index 1873a16..01b02d7 100644 --- a/utils/web3x/ippt-abi.json +++ b/utils/web3x/ippt-abi.json @@ -15,5 +15,46 @@ ], "stateMutability": "nonpayable", "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "spender", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "decimals", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" } ] diff --git a/utils/web3x/usdt-abi.json b/utils/web3x/usdt-abi.json index c192218..1e60985 100644 --- a/utils/web3x/usdt-abi.json +++ b/utils/web3x/usdt-abi.json @@ -1,88 +1,122 @@ [ { + "constant": true, "inputs": [], + "name": "name", + "outputs": [ + { + "name": "", + "type": "string" + } + ], "payable": false, - "stateMutability": "nonpayable", - "type": "constructor" + "stateMutability": "view", + "type": "function" }, { - "anonymous": false, + "constant": false, "inputs": [ { - "indexed": true, - "internalType": "address", - "name": "owner", + "name": "_upgradedAddress", "type": "address" - }, + } + ], + "name": "deprecate", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ { - "indexed": true, - "internalType": "address", - "name": "spender", + "name": "_spender", "type": "address" }, { - "indexed": false, - "internalType": "uint256", - "name": "value", + "name": "_value", "type": "uint256" } ], - "name": "Approval", - "type": "event" + "name": "approve", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" }, { - "anonymous": false, + "constant": true, + "inputs": [], + "name": "deprecated", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, "inputs": [ { - "indexed": true, - "internalType": "address", - "name": "previousOwner", + "name": "_evilUser", "type": "address" - }, + } + ], + "name": "addBlackList", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [ { - "indexed": true, - "internalType": "address", - "name": "newOwner", - "type": "address" + "name": "", + "type": "uint256" } ], - "name": "OwnershipTransferred", - "type": "event" + "payable": false, + "stateMutability": "view", + "type": "function" }, { - "anonymous": false, + "constant": false, "inputs": [ { - "indexed": true, - "internalType": "address", - "name": "from", + "name": "_from", "type": "address" }, { - "indexed": true, - "internalType": "address", - "name": "to", + "name": "_to", "type": "address" }, { - "indexed": false, - "internalType": "uint256", - "name": "value", + "name": "_value", "type": "uint256" } ], - "name": "Transfer", - "type": "event" + "name": "transferFrom", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" }, { "constant": true, "inputs": [], - "name": "_decimals", + "name": "upgradedAddress", "outputs": [ { - "internalType": "uint8", "name": "", - "type": "uint8" + "type": "address" } ], "payable": false, @@ -91,13 +125,17 @@ }, { "constant": true, - "inputs": [], - "name": "_name", + "inputs": [ + { + "name": "", + "type": "address" + } + ], + "name": "balances", "outputs": [ { - "internalType": "string", "name": "", - "type": "string" + "type": "uint256" } ], "payable": false, @@ -107,12 +145,11 @@ { "constant": true, "inputs": [], - "name": "_symbol", + "name": "decimals", "outputs": [ { - "internalType": "string", "name": "", - "type": "string" + "type": "uint256" } ], "payable": false, @@ -121,22 +158,24 @@ }, { "constant": true, - "inputs": [ - { - "internalType": "address", - "name": "owner", - "type": "address" - }, + "inputs": [], + "name": "maximumFee", + "outputs": [ { - "internalType": "address", - "name": "spender", - "type": "address" + "name": "", + "type": "uint256" } ], - "name": "allowance", + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "_totalSupply", "outputs": [ { - "internalType": "uint256", "name": "", "type": "uint256" } @@ -147,43 +186,47 @@ }, { "constant": false, + "inputs": [], + "name": "unpause", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, "inputs": [ { - "internalType": "address", - "name": "spender", + "name": "_maker", "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" } ], - "name": "approve", + "name": "getBlackListStatus", "outputs": [ { - "internalType": "bool", "name": "", "type": "bool" } ], "payable": false, - "stateMutability": "nonpayable", + "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [ { - "internalType": "address", - "name": "account", + "name": "", + "type": "address" + }, + { + "name": "", "type": "address" } ], - "name": "balanceOf", + "name": "allowed", "outputs": [ { - "internalType": "uint256", "name": "", "type": "uint256" } @@ -195,12 +238,11 @@ { "constant": true, "inputs": [], - "name": "decimals", + "name": "paused", "outputs": [ { - "internalType": "uint256", "name": "", - "type": "uint256" + "type": "bool" } ], "payable": false, @@ -208,28 +250,30 @@ "type": "function" }, { - "constant": false, + "constant": true, "inputs": [ { - "internalType": "address", - "name": "spender", + "name": "who", "type": "address" - }, - { - "internalType": "uint256", - "name": "subtractedValue", - "type": "uint256" } ], - "name": "decreaseAllowance", + "name": "balanceOf", "outputs": [ { - "internalType": "bool", "name": "", - "type": "bool" + "type": "uint256" } ], "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "pause", + "outputs": [], + "payable": false, "stateMutability": "nonpayable", "type": "function" }, @@ -239,7 +283,6 @@ "name": "getOwner", "outputs": [ { - "internalType": "address", "name": "", "type": "address" } @@ -248,28 +291,66 @@ "stateMutability": "view", "type": "function" }, + { + "constant": true, + "inputs": [], + "name": "owner", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "symbol", + "outputs": [ + { + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, { "constant": false, "inputs": [ { - "internalType": "address", - "name": "spender", + "name": "_to", "type": "address" }, { - "internalType": "uint256", - "name": "addedValue", + "name": "_value", "type": "uint256" } ], - "name": "increaseAllowance", - "outputs": [ + "name": "transfer", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ { - "internalType": "bool", - "name": "", - "type": "bool" + "name": "newBasisPoints", + "type": "uint256" + }, + { + "name": "newMaxFee", + "type": "uint256" } ], + "name": "setParams", + "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" @@ -278,32 +359,47 @@ "constant": false, "inputs": [ { - "internalType": "uint256", "name": "amount", "type": "uint256" } ], - "name": "mint", - "outputs": [ + "name": "issue", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ { - "internalType": "bool", - "name": "", - "type": "bool" + "name": "amount", + "type": "uint256" } ], + "name": "redeem", + "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, - "inputs": [], - "name": "name", + "inputs": [ + { + "name": "_owner", + "type": "address" + }, + { + "name": "_spender", + "type": "address" + } + ], + "name": "allowance", "outputs": [ { - "internalType": "string", - "name": "", - "type": "string" + "name": "remaining", + "type": "uint256" } ], "payable": false, @@ -313,22 +409,45 @@ { "constant": true, "inputs": [], - "name": "owner", + "name": "basisPointsRate", "outputs": [ { - "internalType": "address", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { "name": "", "type": "address" } ], + "name": "isBlackListed", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, - "inputs": [], - "name": "renounceOwnership", + "inputs": [ + { + "name": "_clearedUser", + "type": "address" + } + ], + "name": "removeBlackList", "outputs": [], "payable": false, "stateMutability": "nonpayable", @@ -337,12 +456,11 @@ { "constant": true, "inputs": [], - "name": "symbol", + "name": "MAX_UINT", "outputs": [ { - "internalType": "string", "name": "", - "type": "string" + "type": "uint256" } ], "payable": false, @@ -350,90 +468,204 @@ "type": "function" }, { - "constant": true, - "inputs": [], - "name": "totalSupply", - "outputs": [ + "constant": false, + "inputs": [ { - "internalType": "uint256", - "name": "", - "type": "uint256" + "name": "newOwner", + "type": "address" } ], + "name": "transferOwnership", + "outputs": [], "payable": false, - "stateMutability": "view", + "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { - "internalType": "address", - "name": "recipient", + "name": "_blackListedUser", "type": "address" + } + ], + "name": "destroyBlackFunds", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "name": "_initialSupply", + "type": "uint256" + }, + { + "name": "_name", + "type": "string" + }, + { + "name": "_symbol", + "type": "string" }, { - "internalType": "uint256", + "name": "_decimals", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, "name": "amount", "type": "uint256" } ], - "name": "transfer", - "outputs": [ + "name": "Issue", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ { - "internalType": "bool", - "name": "", - "type": "bool" + "indexed": false, + "name": "amount", + "type": "uint256" } ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" + "name": "Redeem", + "type": "event" }, { - "constant": false, + "anonymous": false, "inputs": [ { - "internalType": "address", - "name": "sender", + "indexed": false, + "name": "newAddress", "type": "address" + } + ], + "name": "Deprecate", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "feeBasisPoints", + "type": "uint256" }, { - "internalType": "address", - "name": "recipient", + "indexed": false, + "name": "maxFee", + "type": "uint256" + } + ], + "name": "Params", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "_blackListedUser", "type": "address" }, { - "internalType": "uint256", - "name": "amount", + "indexed": false, + "name": "_balance", "type": "uint256" } ], - "name": "transferFrom", - "outputs": [ + "name": "DestroyedBlackFunds", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ { - "internalType": "bool", - "name": "", - "type": "bool" + "indexed": false, + "name": "_user", + "type": "address" } ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" + "name": "AddedBlackList", + "type": "event" }, { - "constant": false, + "anonymous": false, "inputs": [ { - "internalType": "address", - "name": "newOwner", + "indexed": false, + "name": "_user", "type": "address" } ], - "name": "transferOwnership", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" + "name": "RemovedBlackList", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "from", + "type": "address" + }, + { + "indexed": true, + "name": "to", + "type": "address" + }, + { + "indexed": false, + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [], + "name": "Pause", + "type": "event" + }, + { + "anonymous": false, + "inputs": [], + "name": "Unpause", + "type": "event" } -] +] \ No newline at end of file