From 17d4dd4fd04956e1577a22979f212defcca25bc8 Mon Sep 17 00:00:00 2001 From: Michael Kim Date: Thu, 5 Oct 2023 12:15:42 +0900 Subject: [PATCH 1/3] [Contract] Change the shop's phone number to an address --- .../contracts/contracts/ShopCollection.sol | 97 +++++++------------ .../contracts/test/02-ShopCollection.test.ts | 25 ++--- packages/contracts/test/03-Ledger.test.ts | 27 +++--- 3 files changed, 55 insertions(+), 94 deletions(-) diff --git a/packages/contracts/contracts/ShopCollection.sol b/packages/contracts/contracts/ShopCollection.sol index 5b7b9e78..676025f3 100644 --- a/packages/contracts/contracts/ShopCollection.sol +++ b/packages/contracts/contracts/ShopCollection.sol @@ -2,14 +2,10 @@ pragma solidity ^0.8.0; -import "del-osx-artifacts/contracts/PhoneLinkCollection.sol"; import "./ValidatorCollection.sol"; /// @notice 상점컬랙션 contract ShopCollection { - /// @notice Hash value of a blank string - bytes32 public constant NULL = 0x32105b1d0b88ada155176b58ee08b45c31e4f2f7337475831982c313533b880c; - /// @notice 검증자의 상태코드 enum WithdrawStatus { CLOSE, @@ -33,7 +29,7 @@ contract ShopCollection { string shopId; // 상점 아이디 uint256 provideWaitTime; // 제품구매 후 포인트 지급시간 uint256 providePercent; // 구매금액에 대한 포인트 지급량 - bytes32 phone; // 상점주의 전화번호 + address account; // 상점주의 지갑주소 uint256 providedPoint; // 제공된 포인트 총량 uint256 usedPoint; // 사용된 포인트 총량 uint256 settledPoint; // 정산된 포인트 총량 @@ -43,20 +39,15 @@ contract ShopCollection { } mapping(string => ShopData) private shops; - mapping(bytes32 => ShopData) private shopsByPhone; string[] private items; address public validatorAddress; - address public linkCollectionAddress; ValidatorCollection private validatorCollection; - PhoneLinkCollection private linkCollection; /// @notice 상점이 추가될 때 발생되는 이벤트 - event AddedShop(string shopId, uint256 provideWaitTime, uint256 providePercent, bytes32 phone); - /// @notice 상점의 정보가 업데이트 때 발생되는 이벤트 - event UpdatedShop(string shopId, uint256 provideWaitTime, uint256 providePercent, bytes32 phone); + event AddedShop(string shopId, uint256 provideWaitTime, uint256 providePercent, address account); /// @notice 상점의 포인트가 증가할 때 발생되는 이벤트 event IncreasedProvidedPoint(string shopId, uint256 increase, uint256 total, string purchaseId); /// @notice 사용자의 포인트가 증가할 때 발생되는 이벤트 @@ -72,12 +63,10 @@ contract ShopCollection { /// @notice 생성자 /// @param _validatorAddress 검증자컬랙션의 주소 - constructor(address _validatorAddress, address _linkCollectionAddress) { + constructor(address _validatorAddress) { validatorAddress = _validatorAddress; - linkCollectionAddress = _linkCollectionAddress; validatorCollection = ValidatorCollection(_validatorAddress); - linkCollection = PhoneLinkCollection(_linkCollectionAddress); ledgerAddress = address(0x00); deployer = msg.sender; @@ -110,43 +99,35 @@ contract ShopCollection { string calldata _shopId, uint256 _provideWaitTime, uint256 _providePercent, - bytes32 _phone + address _account ) public onlyValidator(msg.sender) { - _add(_shopId, _provideWaitTime, _providePercent, _phone); + _add(_shopId, _provideWaitTime, _providePercent, _account); } - function _add(string calldata _shopId, uint256 _provideWaitTime, uint256 _providePercent, bytes32 _phone) internal { - require(_phone != NULL, "Invalid phone"); - - if (shops[_shopId].status == ShopStatus.INVALID) { - ShopData memory data = ShopData({ - shopId: _shopId, - provideWaitTime: _provideWaitTime, - providePercent: _providePercent, - phone: _phone, - providedPoint: 0, - usedPoint: 0, - settledPoint: 0, - withdrawnPoint: 0, - status: ShopStatus.ACTIVE, - withdrawData: WithdrawData({ amount: 0, account: address(0x0), status: WithdrawStatus.CLOSE }) - }); - items.push(_shopId); - shops[_shopId] = data; - shopsByPhone[_phone] = data; - emit AddedShop(_shopId, _provideWaitTime, _providePercent, _phone); - } else { - shops[_shopId].provideWaitTime = _provideWaitTime; - shops[_shopId].providePercent = _providePercent; - if (shops[_shopId].phone != _phone) { - shops[_shopId].phone = _phone; - ShopData memory data = shops[_shopId]; - bytes32 oldPhone = shops[_shopId].phone; - delete shopsByPhone[oldPhone]; - shopsByPhone[_phone] = data; - } - emit UpdatedShop(_shopId, _provideWaitTime, _providePercent, _phone); - } + function _add( + string calldata _shopId, + uint256 _provideWaitTime, + uint256 _providePercent, + address _account + ) internal { + require(_account != address(0x0), "Invalid address"); + require(shops[_shopId].status == ShopStatus.INVALID, "Invalid shopId"); + + ShopData memory data = ShopData({ + shopId: _shopId, + provideWaitTime: _provideWaitTime, + providePercent: _providePercent, + account: _account, + providedPoint: 0, + usedPoint: 0, + settledPoint: 0, + withdrawnPoint: 0, + status: ShopStatus.ACTIVE, + withdrawData: WithdrawData({ amount: 0, account: address(0x0), status: WithdrawStatus.CLOSE }) + }); + items.push(_shopId); + shops[_shopId] = data; + emit AddedShop(_shopId, _provideWaitTime, _providePercent, _account); } /// @notice 지급된 총 마일지리를 누적한다 @@ -193,12 +174,6 @@ contract ShopCollection { return shops[_shopId]; } - /// @notice 상점 데이터를 리턴한다 - /// @param _phone 상점의 전화번호 - function shopByPhoneOf(bytes32 _phone) public view returns (ShopData memory) { - return shopsByPhone[_phone]; - } - /// @notice 상점의 아이디를 리턴한다 /// @param _idx 배열의 순번 function shopIdOf(uint256 _idx) public view returns (string memory) { @@ -223,9 +198,7 @@ contract ShopCollection { function openWithdrawal(string calldata _shopId, uint256 _amount) public { ShopData memory shop = shops[_shopId]; - bytes32 phone = linkCollection.toPhone(msg.sender); - require(phone != bytes32(0x00), "Unregistered phone-address"); - require(shop.phone == phone, "Invalid address"); + require(shop.account == msg.sender, "Invalid address"); require(_amount <= shop.settledPoint - shop.withdrawnPoint, "Insufficient withdrawal amount"); require(shop.withdrawData.status == WithdrawStatus.CLOSE, "Already opened"); @@ -239,20 +212,16 @@ contract ShopCollection { /// @notice 정산금의 인출을 마감한다. 상점주인만이 실행가능 /// @param _shopId 상점아이디 - /// @param _amount 인출금 - function closeWithdrawal(string calldata _shopId, uint256 _amount) public { + function closeWithdrawal(string calldata _shopId) public { ShopData memory shop = shops[_shopId]; - bytes32 phone = linkCollection.toPhone(msg.sender); - require(phone != bytes32(0x00), "Unregistered phone-address"); - require(shop.phone == phone, "Invalid address"); + require(shop.account == msg.sender, "Invalid address"); require(shop.withdrawData.status == WithdrawStatus.OPEN, "Not opened"); - require(shop.withdrawData.amount == _amount, "Inconsistent amount"); shops[_shopId].withdrawData.status = WithdrawStatus.CLOSE; shops[_shopId].withdrawnPoint += shop.withdrawData.amount; - emit ClosedWithdrawal(_shopId, _amount, msg.sender); + emit ClosedWithdrawal(_shopId, shops[_shopId].withdrawData.amount, msg.sender); } } diff --git a/packages/contracts/test/02-ShopCollection.test.ts b/packages/contracts/test/02-ShopCollection.test.ts index 2a5b7720..d30f00cf 100644 --- a/packages/contracts/test/02-ShopCollection.test.ts +++ b/packages/contracts/test/02-ShopCollection.test.ts @@ -1,6 +1,6 @@ import { Amount } from "../src/utils/Amount"; import { ContractUtils } from "../src/utils/ContractUtils"; -import { PhoneLinkCollection, ShopCollection, Token, ValidatorCollection } from "../typechain-types"; +import { ShopCollection, Token, ValidatorCollection } from "../typechain-types"; import "@nomiclabs/hardhat-ethers"; import "@nomiclabs/hardhat-waffle"; @@ -19,9 +19,7 @@ describe("Test for ShopCollection", () => { provider.getWallets(); const validators = [validator1, validator2, validator3]; - const linkValidators = [validator1]; const shopWallets = [shop1, shop2, shop3, shop4, shop5]; - let linkCollectionContract: PhoneLinkCollection; let validatorContract: ValidatorCollection; let tokenContract: Token; let shopCollection: ShopCollection; @@ -29,13 +27,6 @@ describe("Test for ShopCollection", () => { const amount = Amount.make(20_000, 18); before(async () => { - const linkCollectionFactory = await hre.ethers.getContractFactory("PhoneLinkCollection"); - linkCollectionContract = (await linkCollectionFactory - .connect(deployer) - .deploy(linkValidators.map((m) => m.address))) as PhoneLinkCollection; - await linkCollectionContract.deployed(); - await linkCollectionContract.deployTransaction.wait(); - const tokenFactory = await hre.ethers.getContractFactory("Token"); tokenContract = (await tokenFactory.connect(deployer).deploy(deployer.address, "Sample", "SAM")) as Token; await tokenContract.deployed(); @@ -66,7 +57,7 @@ describe("Test for ShopCollection", () => { const shopCollectionFactory = await hre.ethers.getContractFactory("ShopCollection"); shopCollection = (await shopCollectionFactory .connect(deployer) - .deploy(validatorContract.address, linkCollectionContract.address)) as ShopCollection; + .deploy(validatorContract.address)) as ShopCollection; await shopCollection.deployed(); await shopCollection.deployTransaction.wait(); }); @@ -119,11 +110,15 @@ describe("Test for ShopCollection", () => { ]; it("Not validator", async () => { - const phoneHash = ContractUtils.getPhoneHash(shopData[0].phone); await expect( shopCollection .connect(user1) - .add(shopData[0].shopId, shopData[0].provideWaitTime, shopData[0].providePercent, phoneHash) + .add( + shopData[0].shopId, + shopData[0].provideWaitTime, + shopData[0].providePercent, + shopData[0].account + ) ).to.revertedWith("Not validator"); }); @@ -133,10 +128,10 @@ describe("Test for ShopCollection", () => { await expect( shopCollection .connect(validator1) - .add(elem.shopId, elem.provideWaitTime, elem.providePercent, phoneHash) + .add(elem.shopId, elem.provideWaitTime, elem.providePercent, elem.account) ) .to.emit(shopCollection, "AddedShop") - .withArgs(elem.shopId, elem.provideWaitTime, elem.providePercent, phoneHash); + .withArgs(elem.shopId, elem.provideWaitTime, elem.providePercent, elem.account); } expect(await shopCollection.shopsLength()).to.equal(shopData.length); }); diff --git a/packages/contracts/test/03-Ledger.test.ts b/packages/contracts/test/03-Ledger.test.ts index 879ce267..deb385d8 100644 --- a/packages/contracts/test/03-Ledger.test.ts +++ b/packages/contracts/test/03-Ledger.test.ts @@ -151,7 +151,7 @@ describe("Test for Ledger", () => { const shopCollectionFactory = await hre.ethers.getContractFactory("ShopCollection"); shopCollection = (await shopCollectionFactory .connect(deployer) - .deploy(validatorContract.address, linkCollectionContract.address)) as ShopCollection; + .deploy(validatorContract.address)) as ShopCollection; await shopCollection.deployed(); await shopCollection.deployTransaction.wait(); }; @@ -186,6 +186,7 @@ describe("Test for Ledger", () => { }; let requestId: string; + /* context("Save Purchase Data & Pay (point, token)", () => { const userData: IUserData[] = [ { @@ -315,14 +316,13 @@ describe("Test for Ledger", () => { context("Prepare shop data", () => { it("Add Shop Data", async () => { for (const elem of shopData) { - const phoneHash = ContractUtils.getPhoneHash(elem.phone); await expect( shopCollection .connect(validator1) - .add(elem.shopId, elem.provideWaitTime, elem.providePercent, phoneHash) + .add(elem.shopId, elem.provideWaitTime, elem.providePercent, elem.account) ) .to.emit(shopCollection, "AddedShop") - .withArgs(elem.shopId, elem.provideWaitTime, elem.providePercent, phoneHash); + .withArgs(elem.shopId, elem.provideWaitTime, elem.providePercent, elem.account); } expect(await shopCollection.shopsLength()).to.equal(shopData.length); }); @@ -1230,14 +1230,13 @@ describe("Test for Ledger", () => { context("Prepare shop data", () => { it("Add Shop Data", async () => { for (const elem of shopData) { - const phoneHash = ContractUtils.getPhoneHash(elem.phone); await expect( shopCollection .connect(validator1) - .add(elem.shopId, elem.provideWaitTime, elem.providePercent, phoneHash) + .add(elem.shopId, elem.provideWaitTime, elem.providePercent, elem.account) ) .to.emit(shopCollection, "AddedShop") - .withArgs(elem.shopId, elem.provideWaitTime, elem.providePercent, phoneHash); + .withArgs(elem.shopId, elem.provideWaitTime, elem.providePercent, elem.account); } expect(await shopCollection.shopsLength()).to.equal(shopData.length); }); @@ -1442,14 +1441,13 @@ describe("Test for Ledger", () => { context("Prepare shop data", () => { it("Add Shop Data", async () => { for (const elem of shopData) { - const phoneHash = ContractUtils.getPhoneHash(elem.phone); await expect( shopCollection .connect(validator1) - .add(elem.shopId, elem.provideWaitTime, elem.providePercent, phoneHash) + .add(elem.shopId, elem.provideWaitTime, elem.providePercent, elem.account) ) .to.emit(shopCollection, "AddedShop") - .withArgs(elem.shopId, elem.provideWaitTime, elem.providePercent, phoneHash); + .withArgs(elem.shopId, elem.provideWaitTime, elem.providePercent, elem.account); } expect(await shopCollection.shopsLength()).to.equal(shopData.length); }); @@ -1743,7 +1741,7 @@ describe("Test for Ledger", () => { await expect( shopCollection .connect(shopWallets[shopIndex].connect(hre.waffle.provider)) - .closeWithdrawal(shop.shopId, amount2) + .closeWithdrawal(shop.shopId) ) .to.emit(shopCollection, "ClosedWithdrawal") .withNamedArgs({ @@ -1756,7 +1754,7 @@ describe("Test for Ledger", () => { }); }); }); - +*/ context("Multi Currency", () => { const userData: IUserData[] = [ { @@ -1908,14 +1906,13 @@ describe("Test for Ledger", () => { context("Prepare shop data", () => { it("Add Shop Data", async () => { for (const elem of shopData) { - const phoneHash = ContractUtils.getPhoneHash(elem.phone); await expect( shopCollection .connect(validator1) - .add(elem.shopId, elem.provideWaitTime, elem.providePercent, phoneHash) + .add(elem.shopId, elem.provideWaitTime, elem.providePercent, elem.account) ) .to.emit(shopCollection, "AddedShop") - .withArgs(elem.shopId, elem.provideWaitTime, elem.providePercent, phoneHash); + .withArgs(elem.shopId, elem.provideWaitTime, elem.providePercent, elem.account); } expect(await shopCollection.shopsLength()).to.equal(shopData.length); }); From bf26fd45a01819e9a1751367027ec6314b1e140f Mon Sep 17 00:00:00 2001 From: Michael Kim Date: Fri, 6 Oct 2023 08:42:39 +0900 Subject: [PATCH 2/3] [Contract] Change shop information to be created by shop owners themselves --- packages/contracts/contracts/Ledger.sol | 34 +- .../contracts/contracts/ShopCollection.sol | 140 ++--- .../contracts/ValidatorCollection.sol | 1 - .../bosagora_devnet/05_shopCollection.ts | 121 +---- .../deploy/bosagora_devnet/06_ledger.ts | 79 ++- packages/contracts/deploy/data/shops.json | 40 +- packages/contracts/deploy/data/users.json | 200 ++++---- packages/contracts/npm/artifacts.ts | 9 +- packages/contracts/src/utils/ContractUtils.ts | 10 +- .../contracts/test/02-ShopCollection.test.ts | 150 +++--- packages/contracts/test/03-Ledger.test.ts | 246 ++++----- packages/faker/scripts/createShopId.ts | 18 + packages/faker/src/data/shops.json | 70 ++- packages/faker/src/data/users.json | 200 ++++---- .../faker/src/scheduler/DefaultScheduler.ts | 23 +- packages/faker/src/types/index.ts | 3 + packages/faker/src/utils/ContractUtils.ts | 40 +- packages/relay/src/routers/DefaultRouter.ts | 8 +- packages/relay/src/utils/ContractUtils.ts | 10 +- packages/relay/test/Endpoints.test.ts | 94 +++- packages/subgraph/generated/Ledger/Ledger.ts | 177 +++++-- .../ShopCollection/ShopCollection.ts | 482 +++++++++++++----- packages/subgraph/generated/schema.ts | 178 +++++-- .../manifest/subgraph.placeholder.yaml | 33 +- packages/subgraph/schema.graphql | 34 +- packages/subgraph/src/ledger.ts | 14 +- packages/subgraph/src/shop-collection.ts | 30 +- packages/subgraph/src/utils.ts | 3 + 28 files changed, 1467 insertions(+), 980 deletions(-) create mode 100644 packages/faker/scripts/createShopId.ts diff --git a/packages/contracts/contracts/Ledger.sol b/packages/contracts/contracts/Ledger.sol index 72690276..6c932ae3 100644 --- a/packages/contracts/contracts/Ledger.sol +++ b/packages/contracts/contracts/Ledger.sol @@ -33,7 +33,7 @@ contract Ledger { uint256 timestamp; uint256 amount; string currency; - string shopId; + bytes32 shopId; uint32 method; address account; bytes32 phone; @@ -43,7 +43,7 @@ contract Ledger { string purchaseId; uint256 amount; string currency; - string shopId; + bytes32 shopId; address account; bytes signature; } @@ -73,7 +73,7 @@ contract Ledger { uint256 timestamp, uint256 amount, string currency, - string shopId, + bytes32 shopId, uint32 method, address account, bytes32 phone @@ -85,7 +85,7 @@ contract Ledger { uint256 value, uint256 balancePoint, string purchaseId, - string shopId + bytes32 shopId ); /// @notice 포인트가 지급될 때 발생되는 이벤트 event ProvidedUnPayablePoint( @@ -94,7 +94,7 @@ contract Ledger { uint256 value, uint256 balancePoint, string purchaseId, - string shopId + bytes32 shopId ); /// @notice 사용가능한 포인트로 변환될 때 발생되는 이벤트 event ChangedToPayablePoint( @@ -107,7 +107,7 @@ contract Ledger { /// @notice 포인트가 정산될 때 발생되는 이벤트 event ProvidedTokenForSettlement( address account, - string shopId, + bytes32 shopId, uint256 providedAmountPoint, uint256 providedAmountToken, uint256 value, @@ -121,7 +121,7 @@ contract Ledger { uint256 value, uint256 balanceToken, string purchaseId, - string shopId + bytes32 shopId ); /// @notice 포인트로 지불을 완료했을 때 발생하는 이벤트 event PaidPoint( @@ -133,7 +133,7 @@ contract Ledger { uint256 balancePoint, string purchaseId, uint256 purchaseAmount, - string shopId + bytes32 shopId ); /// @notice 토큰으로 지불을 완료했을 때 발생하는 이벤트 event PaidToken( @@ -145,7 +145,7 @@ contract Ledger { uint256 balanceToken, string purchaseId, uint256 purchaseAmount, - string shopId + bytes32 shopId ); /// @notice 토큰을 예치했을 때 발생하는 이벤트 event Deposited(address account, uint256 depositAmount, uint256 value, uint256 balanceToken); @@ -247,12 +247,7 @@ contract Ledger { /// @param _amount 지급할 포인트 /// @param _purchaseId 구매 아이디 /// @param _shopId 구매한 가맹점 아이디 - function providePoint( - address _account, - uint256 _amount, - string calldata _purchaseId, - string calldata _shopId - ) internal { + function providePoint(address _account, uint256 _amount, string calldata _purchaseId, bytes32 _shopId) internal { pointBalances[_account] += _amount; emit ProvidedPoint(_account, _amount, _amount, pointBalances[_account], _purchaseId, _shopId); } @@ -267,7 +262,7 @@ contract Ledger { bytes32 _phone, uint256 _amount, string calldata _purchaseId, - string calldata _shopId + bytes32 _shopId ) internal { unPayablePointBalances[_phone] += _amount; emit ProvidedUnPayablePoint(_phone, _amount, _amount, unPayablePointBalances[_phone], _purchaseId, _shopId); @@ -279,12 +274,7 @@ contract Ledger { /// @param _amount 지급할 토큰 /// @param _purchaseId 구매 아이디 /// @param _shopId 구매한 가맹점 아이디 - function provideToken( - address _account, - uint256 _amount, - string calldata _purchaseId, - string calldata _shopId - ) internal { + function provideToken(address _account, uint256 _amount, string calldata _purchaseId, bytes32 _shopId) internal { uint256 amountToken = convertPointToToken(_amount); require(tokenBalances[foundationAccount] >= amountToken, "Insufficient foundation balance"); diff --git a/packages/contracts/contracts/ShopCollection.sol b/packages/contracts/contracts/ShopCollection.sol index 676025f3..c450bfec 100644 --- a/packages/contracts/contracts/ShopCollection.sol +++ b/packages/contracts/contracts/ShopCollection.sol @@ -2,8 +2,6 @@ pragma solidity ^0.8.0; -import "./ValidatorCollection.sol"; - /// @notice 상점컬랙션 contract ShopCollection { /// @notice 검증자의 상태코드 @@ -14,7 +12,6 @@ contract ShopCollection { struct WithdrawData { uint256 amount; - address account; WithdrawStatus status; } @@ -26,7 +23,8 @@ contract ShopCollection { /// @notice 상점의 데이터 struct ShopData { - string shopId; // 상점 아이디 + bytes32 shopId; // 상점 아이디 + string name; // 상점 이름 uint256 provideWaitTime; // 제품구매 후 포인트 지급시간 uint256 providePercent; // 구매금액에 대한 포인트 지급량 address account; // 상점주의 지갑주소 @@ -36,38 +34,36 @@ contract ShopCollection { uint256 withdrawnPoint; // 정산된 포인트 총량 ShopStatus status; WithdrawData withdrawData; + uint256 itemIndex; + uint256 accountIndex; } - mapping(string => ShopData) private shops; - - string[] private items; - - address public validatorAddress; + mapping(bytes32 => ShopData) private shops; + mapping(address => bytes32[]) private shopIdByAddress; - ValidatorCollection private validatorCollection; + bytes32[] private items; /// @notice 상점이 추가될 때 발생되는 이벤트 - event AddedShop(string shopId, uint256 provideWaitTime, uint256 providePercent, address account); + event AddedShop(bytes32 shopId, string name, uint256 provideWaitTime, uint256 providePercent, address account); + /// @notice 상점의 정보가 변경될 때 발생되는 이벤트 + event UpdatedShop(bytes32 shopId, string name, uint256 provideWaitTime, uint256 providePercent, address account); + /// @notice 상점의 정보가 삭제될 때 발생되는 이벤트 + event RemovedShop(bytes32 shopId); /// @notice 상점의 포인트가 증가할 때 발생되는 이벤트 - event IncreasedProvidedPoint(string shopId, uint256 increase, uint256 total, string purchaseId); + event IncreasedProvidedPoint(bytes32 shopId, uint256 increase, uint256 total, string purchaseId); /// @notice 사용자의 포인트가 증가할 때 발생되는 이벤트 - event IncreasedUsedPoint(string shopId, uint256 increase, uint256 total, string purchaseId); + event IncreasedUsedPoint(bytes32 shopId, uint256 increase, uint256 total, string purchaseId); /// @notice 정산된 마일리가 증가할 때 발생되는 이벤트 - event IncreasedSettledPoint(string shopId, uint256 increase, uint256 total, string purchaseId); + event IncreasedSettledPoint(bytes32 shopId, uint256 increase, uint256 total, string purchaseId); - event OpenedWithdrawal(string shopId, uint256 amount, address account); - event ClosedWithdrawal(string shopId, uint256 amount, address account); + event OpenedWithdrawal(bytes32 shopId, uint256 amount, address account); + event ClosedWithdrawal(bytes32 shopId, uint256 amount, address account); address public ledgerAddress; address public deployer; /// @notice 생성자 - /// @param _validatorAddress 검증자컬랙션의 주소 - constructor(address _validatorAddress) { - validatorAddress = _validatorAddress; - - validatorCollection = ValidatorCollection(_validatorAddress); - + constructor() { ledgerAddress = address(0x00); deployer = msg.sender; } @@ -79,59 +75,90 @@ contract ShopCollection { deployer = address(0x00); } - /// @notice 검증자들만 호출할 수 있도록 해준다. - modifier onlyValidator(address _account) { - require(validatorCollection.isActiveValidator(_account), "Not validator"); - _; - } - /// @notice 원장 컨트랙트에서만 호출될 수 있도록 해준다. modifier onlyLedger() { require(msg.sender == ledgerAddress, "Not ledger"); _; } + /// @notice 이용할 수 있는 아이디 인지 알려준다. + /// @param _shopId 상점 아이디 + function isAvailableId(bytes32 _shopId) public view returns (bool) { + if (shops[_shopId].status == ShopStatus.INVALID) return true; + else return false; + } + /// @notice 상점을 추가한다 /// @param _shopId 상점 아이디 + /// @param _name 상점이름 /// @param _provideWaitTime 제품구매 후 포인트가 지급될 시간 /// @param _providePercent 구매금액에 대한 포인트 지급량 - function add( - string calldata _shopId, - uint256 _provideWaitTime, - uint256 _providePercent, - address _account - ) public onlyValidator(msg.sender) { - _add(_shopId, _provideWaitTime, _providePercent, _account); - } - - function _add( - string calldata _shopId, - uint256 _provideWaitTime, - uint256 _providePercent, - address _account - ) internal { - require(_account != address(0x0), "Invalid address"); + function add(bytes32 _shopId, string calldata _name, uint256 _provideWaitTime, uint256 _providePercent) public { require(shops[_shopId].status == ShopStatus.INVALID, "Invalid shopId"); ShopData memory data = ShopData({ shopId: _shopId, + name: _name, provideWaitTime: _provideWaitTime, providePercent: _providePercent, - account: _account, + account: msg.sender, providedPoint: 0, usedPoint: 0, settledPoint: 0, withdrawnPoint: 0, status: ShopStatus.ACTIVE, - withdrawData: WithdrawData({ amount: 0, account: address(0x0), status: WithdrawStatus.CLOSE }) + withdrawData: WithdrawData({ amount: 0, status: WithdrawStatus.CLOSE }), + itemIndex: items.length, + accountIndex: shopIdByAddress[msg.sender].length }); items.push(_shopId); shops[_shopId] = data; - emit AddedShop(_shopId, _provideWaitTime, _providePercent, _account); + shopIdByAddress[msg.sender].push(_shopId); + emit AddedShop(_shopId, _name, _provideWaitTime, _providePercent, msg.sender); + } + + function update(bytes32 _shopId, string calldata _name, uint256 _provideWaitTime, uint256 _providePercent) public { + require(shops[_shopId].status != ShopStatus.INVALID, "Not exist shopId"); + require(shops[_shopId].account == msg.sender, "Not owner"); + + shops[_shopId].name = _name; + shops[_shopId].provideWaitTime = _provideWaitTime; + shops[_shopId].providePercent = _providePercent; + emit UpdatedShop(_shopId, _name, _provideWaitTime, _providePercent, msg.sender); + } + + function remove(bytes32 _shopId) public { + require(shops[_shopId].status != ShopStatus.INVALID, "Not exist shopId"); + require(shops[_shopId].account == msg.sender, "Not owner"); + + uint256 index = shops[_shopId].itemIndex; + uint256 last = items.length - 1; + if (index != last) { + items[index] = items[last]; + shops[items[index]].itemIndex = index; + items.pop(); + } + + index = shops[_shopId].accountIndex; + last = shopIdByAddress[msg.sender].length - 1; + if (index != last) { + shopIdByAddress[msg.sender][index] = shopIdByAddress[msg.sender][last]; + shops[shopIdByAddress[msg.sender][index]].accountIndex = index; + shopIdByAddress[msg.sender].pop(); + } + + delete shops[_shopId]; + emit RemovedShop(_shopId); + } + + /// @notice 지갑주소로 등록한 상점의 아이디들을 리턴한다. + /// @param _account 지갑주소 + function shopsOf(address _account) public view returns (bytes32[] memory) { + return shopIdByAddress[_account]; } /// @notice 지급된 총 마일지리를 누적한다 - function addProvidedPoint(string calldata _shopId, uint256 _amount, string calldata _purchaseId) public onlyLedger { + function addProvidedPoint(bytes32 _shopId, uint256 _amount, string calldata _purchaseId) public onlyLedger { if (shops[_shopId].status != ShopStatus.INVALID) { shops[_shopId].providedPoint += _amount; emit IncreasedProvidedPoint(_shopId, _amount, shops[_shopId].providedPoint, _purchaseId); @@ -139,7 +166,7 @@ contract ShopCollection { } /// @notice 사용된 총 마일지리를 누적한다 - function addUsedPoint(string calldata _shopId, uint256 _amount, string calldata _purchaseId) public onlyLedger { + function addUsedPoint(bytes32 _shopId, uint256 _amount, string calldata _purchaseId) public onlyLedger { if (shops[_shopId].status != ShopStatus.INVALID) { shops[_shopId].usedPoint += _amount; emit IncreasedUsedPoint(_shopId, _amount, shops[_shopId].usedPoint, _purchaseId); @@ -147,7 +174,7 @@ contract ShopCollection { } /// @notice 정산된 총 마일지리를 누적한다 - function addSettledPoint(string calldata _shopId, uint256 _amount, string calldata _purchaseId) public onlyLedger { + function addSettledPoint(bytes32 _shopId, uint256 _amount, string calldata _purchaseId) public onlyLedger { if (shops[_shopId].status != ShopStatus.INVALID) { shops[_shopId].settledPoint += _amount; emit IncreasedSettledPoint(_shopId, _amount, shops[_shopId].settledPoint, _purchaseId); @@ -155,7 +182,7 @@ contract ShopCollection { } /// @notice 정산되어야 할 마일지리의 량을 리턴합니다. - function getSettlementPoint(string calldata _shopId) public view returns (uint256) { + function getSettlementPoint(bytes32 _shopId) public view returns (uint256) { if (shops[_shopId].status == ShopStatus.ACTIVE) { ShopData memory data = shops[_shopId]; if (data.providedPoint + data.settledPoint < data.usedPoint) { @@ -170,13 +197,13 @@ contract ShopCollection { /// @notice 상점 데이터를 리턴한다 /// @param _shopId 상점의 아이디 - function shopOf(string calldata _shopId) public view returns (ShopData memory) { + function shopOf(bytes32 _shopId) public view returns (ShopData memory) { return shops[_shopId]; } /// @notice 상점의 아이디를 리턴한다 /// @param _idx 배열의 순번 - function shopIdOf(uint256 _idx) public view returns (string memory) { + function shopIdOf(uint256 _idx) public view returns (bytes32) { return items[_idx]; } @@ -187,7 +214,7 @@ contract ShopCollection { /// @notice 인출가능한 정산금액을 리턴한다. /// @param _shopId 상점의 아이디 - function withdrawableOf(string calldata _shopId) public view returns (uint256) { + function withdrawableOf(bytes32 _shopId) public view returns (uint256) { ShopData memory shop = shops[_shopId]; return shop.settledPoint - shop.withdrawnPoint; } @@ -195,7 +222,7 @@ contract ShopCollection { /// @notice 정산금의 인출을 요청한다. 상점주인만이 실행가능 /// @param _shopId 상점아이디 /// @param _amount 인출금 - function openWithdrawal(string calldata _shopId, uint256 _amount) public { + function openWithdrawal(bytes32 _shopId, uint256 _amount) public { ShopData memory shop = shops[_shopId]; require(shop.account == msg.sender, "Invalid address"); @@ -203,7 +230,6 @@ contract ShopCollection { require(_amount <= shop.settledPoint - shop.withdrawnPoint, "Insufficient withdrawal amount"); require(shop.withdrawData.status == WithdrawStatus.CLOSE, "Already opened"); - shops[_shopId].withdrawData.account = msg.sender; shops[_shopId].withdrawData.amount = _amount; shops[_shopId].withdrawData.status = WithdrawStatus.OPEN; @@ -212,7 +238,7 @@ contract ShopCollection { /// @notice 정산금의 인출을 마감한다. 상점주인만이 실행가능 /// @param _shopId 상점아이디 - function closeWithdrawal(string calldata _shopId) public { + function closeWithdrawal(bytes32 _shopId) public { ShopData memory shop = shops[_shopId]; require(shop.account == msg.sender, "Invalid address"); diff --git a/packages/contracts/contracts/ValidatorCollection.sol b/packages/contracts/contracts/ValidatorCollection.sol index a271adec..396af8dd 100644 --- a/packages/contracts/contracts/ValidatorCollection.sol +++ b/packages/contracts/contracts/ValidatorCollection.sol @@ -130,7 +130,6 @@ contract ValidatorCollection { return items.length; } - function isActiveValidator(address _account) public view returns (bool) { ValidatorData memory item = validators[_account]; diff --git a/packages/contracts/deploy/bosagora_devnet/05_shopCollection.ts b/packages/contracts/deploy/bosagora_devnet/05_shopCollection.ts index 4ca3a2ed..6d1f919f 100644 --- a/packages/contracts/deploy/bosagora_devnet/05_shopCollection.ts +++ b/packages/contracts/deploy/bosagora_devnet/05_shopCollection.ts @@ -5,9 +5,8 @@ import "hardhat-deploy"; import { DeployFunction } from "hardhat-deploy/types"; // tslint:disable-next-line:no-submodule-imports import { HardhatRuntimeEnvironment } from "hardhat/types"; -import { ContractUtils } from "../../src/utils/ContractUtils"; -import { PhoneLinkCollection, ShopCollection, ValidatorCollection } from "../../typechain-types"; -import { getContractAddress, getPhoneLinkCollectionContractAddress } from "../helpers"; +import { ShopCollection } from "../../typechain-types"; +import { getContractAddress } from "../helpers"; import { Wallet } from "ethers"; @@ -16,33 +15,20 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { const { deployments, getNamedAccounts, ethers } = hre; const { deploy } = deployments; - const { - deployer, - validator1, - validator2, - validator3, - validator4, - validator5, - linkValidator1, - linkValidator2, - linkValidator3, - } = await getNamedAccounts(); - const validators = [validator1, validator2, validator3, validator4, validator5]; - - const validatorContractAddress = await getContractAddress("ValidatorCollection", hre); + const { deployer } = await getNamedAccounts(); const deployResult = await deploy("ShopCollection", { from: deployer, - args: [validatorContractAddress], + args: [], log: true, }); if (deployResult.newlyDeployed) { interface IShopData { shopId: string; + name: string; provideWaitTime: number; providePercent: number; - phone: string; address: string; privateKey: string; } @@ -52,104 +38,11 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { for (const shop of shopData) { const tx = await contract - .connect(await ethers.getSigner(validators[0])) - .add(shop.shopId, shop.provideWaitTime, shop.providePercent, ContractUtils.getPhoneHash(shop.phone)); + .connect(new Wallet(shop.privateKey, ethers.provider)) + .add(shop.shopId, shop.name, shop.provideWaitTime, shop.providePercent); console.log(`Add shop data (tx: ${tx.hash})...`); await tx.wait(); } - - const linkCollectionContractAddress = await getPhoneLinkCollectionContractAddress("PhoneLinkCollection", hre); - const linkCollectionContract = (await ethers.getContractAt( - "PhoneLinkCollection", - linkCollectionContractAddress - )) as PhoneLinkCollection; - - for (const shop of shopData) { - const phoneHash = ContractUtils.getPhoneHash(shop.phone); - if ((await linkCollectionContract.toAddress(phoneHash)) !== shop.address) { - const userNonce = await linkCollectionContract.nonceOf(shop.address); - const userSignature = await ContractUtils.signRequestHash( - new Wallet(shop.privateKey), - phoneHash, - userNonce - ); - const reqId2 = ContractUtils.getRequestId(phoneHash, shop.address, userNonce); - const tx5 = await linkCollectionContract - .connect(await ethers.getSigner(linkValidator1)) - .addRequest(reqId2, phoneHash, shop.address, userSignature); - console.log(`Add phone-address of user (tx: ${tx5.hash})...`); - await tx5.wait(); - - const tx6 = await linkCollectionContract - .connect(await ethers.getSigner(linkValidator1)) - .voteRequest(reqId2); - console.log(`Vote of validator1 (tx: ${tx6.hash})...`); - await tx6.wait(); - - const tx7 = await linkCollectionContract - .connect(await ethers.getSigner(linkValidator2)) - .voteRequest(reqId2); - console.log(`Vote of validator2 (tx: ${tx7.hash})...`); - await tx7.wait(); - - const tx8 = await linkCollectionContract - .connect(await ethers.getSigner(linkValidator1)) - .countVote(reqId2); - console.log(`Count of vote (tx: ${tx8.hash})...`); - await tx8.wait(); - - if ((await linkCollectionContract.toAddress(phoneHash)) === shop.address) { - console.log(`Success ${shop.address}`); - } else { - console.log(`Fail ${shop.address}`); - } - } - } - - const users = JSON.parse(fs.readFileSync("./deploy/data/users.json", "utf8")); - let idx = 0; - for (const user of users) { - if (++idx % 2 === 1) continue; - const userAccount = ContractUtils.getPhoneHash(user.phone); - if ((await linkCollectionContract.toAddress(userAccount)) !== user.address) { - const userNonce = await linkCollectionContract.nonceOf(user.address); - const userSignature = await ContractUtils.signRequestHash( - new Wallet(user.privateKey), - userAccount, - userNonce - ); - const reqId2 = ContractUtils.getRequestId(userAccount, user.address, userNonce); - const tx5 = await linkCollectionContract - .connect(await ethers.getSigner(linkValidator1)) - .addRequest(reqId2, userAccount, user.address, userSignature); - console.log(`Add phone-address of user (tx: ${tx5.hash})...`); - await tx5.wait(); - - const tx6 = await linkCollectionContract - .connect(await ethers.getSigner(linkValidator1)) - .voteRequest(reqId2); - console.log(`Vote of validator1 (tx: ${tx6.hash})...`); - await tx6.wait(); - - const tx7 = await linkCollectionContract - .connect(await ethers.getSigner(linkValidator2)) - .voteRequest(reqId2); - console.log(`Vote of validator2 (tx: ${tx7.hash})...`); - await tx7.wait(); - - const tx8 = await linkCollectionContract - .connect(await ethers.getSigner(linkValidator1)) - .countVote(reqId2); - console.log(`Count of vote (tx: ${tx8.hash})...`); - await tx8.wait(); - - if ((await linkCollectionContract.toAddress(userAccount)) === user.address) { - console.log(`Success ${user.address}`); - } else { - console.log(`Fail ${user.address}`); - } - } - } } }; diff --git a/packages/contracts/deploy/bosagora_devnet/06_ledger.ts b/packages/contracts/deploy/bosagora_devnet/06_ledger.ts index 99229096..3763c3bb 100644 --- a/packages/contracts/deploy/bosagora_devnet/06_ledger.ts +++ b/packages/contracts/deploy/bosagora_devnet/06_ledger.ts @@ -6,8 +6,12 @@ import { DeployFunction } from "hardhat-deploy/types"; import { HardhatRuntimeEnvironment } from "hardhat/types"; import { Amount } from "../../src/utils/Amount"; import { ContractUtils } from "../../src/utils/ContractUtils"; -import { Ledger, ShopCollection, Token } from "../../typechain-types"; -import { getContractAddress, getEmailLinkCollectionContractAddress } from "../helpers"; +import { Ledger, PhoneLinkCollection, ShopCollection, Token } from "../../typechain-types"; +import { + getContractAddress, + getEmailLinkCollectionContractAddress, + getPhoneLinkCollectionContractAddress, +} from "../helpers"; import { Wallet } from "ethers"; @@ -19,7 +23,8 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { const { deployments, getNamedAccounts, ethers } = hre; const { deploy } = deployments; - const { deployer, foundation, settlements, validator1 } = await getNamedAccounts(); + const { deployer, foundation, settlements, fee, validator1, linkValidator1, linkValidator2, linkValidator3 } = + await getNamedAccounts(); const linkCollectionContractAddress = await getEmailLinkCollectionContractAddress("EmailLinkCollection", hre); const tokenContractAddress = await getContractAddress("Token", hre); @@ -32,6 +37,7 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { args: [ foundation, settlements, + fee, tokenContractAddress, validatorContractAddress, linkCollectionContractAddress, @@ -65,27 +71,76 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { console.log(`Deposit foundation's amount (tx: ${tx3.hash})...`); await tx3.wait(); + const linkCollectionContract = (await ethers.getContractAt( + "PhoneLinkCollection", + linkCollectionContractAddress + )) as PhoneLinkCollection; + const users = JSON.parse(fs.readFileSync("./deploy/data/users.json", "utf8")); + let idx = 0; + for (const user of users) { + if (++idx % 2 === 1) continue; + const userAccount = ContractUtils.getPhoneHash(user.phone); + if ((await linkCollectionContract.toAddress(userAccount)) !== user.address) { + const userNonce = await linkCollectionContract.nonceOf(user.address); + const userSignature = await ContractUtils.signRequestHash( + new Wallet(user.privateKey), + userAccount, + userNonce + ); + const reqId2 = ContractUtils.getRequestId(userAccount, user.address, userNonce); + const tx4 = await linkCollectionContract + .connect(await ethers.getSigner(linkValidator1)) + .addRequest(reqId2, userAccount, user.address, userSignature); + console.log(`Add phone-address of user (tx: ${tx4.hash})...`); + await tx4.wait(); + + const tx5 = await linkCollectionContract + .connect(await ethers.getSigner(linkValidator1)) + .voteRequest(reqId2); + console.log(`Vote of validator1 (tx: ${tx5.hash})...`); + await tx5.wait(); + + const tx6 = await linkCollectionContract + .connect(await ethers.getSigner(linkValidator2)) + .voteRequest(reqId2); + console.log(`Vote of validator2 (tx: ${tx6.hash})...`); + await tx6.wait(); + + const tx7 = await linkCollectionContract + .connect(await ethers.getSigner(linkValidator1)) + .countVote(reqId2); + console.log(`Count of vote (tx: ${tx7.hash})...`); + await tx7.wait(); + + if ((await linkCollectionContract.toAddress(userAccount)) === user.address) { + console.log(`Success ${user.address}`); + } else { + console.log(`Fail ${user.address}`); + } + } + } + for (const user of users) { const balance = await tokenContract.balanceOf(user.address); const depositAmount = balance.div(2); const signer = new Wallet(user.privateKey).connect(ethers.provider); - const tx7 = await tokenContract.connect(signer).approve(ledgerContract.address, depositAmount); - console.log(`Approve user's amount (tx: ${tx7.hash})...`); - await tx7.wait(); - - const tx8 = await ledgerContract.connect(signer).deposit(depositAmount); - console.log(`Deposit user's amount (tx: ${tx8.hash})...`); + const tx8 = await tokenContract.connect(signer).approve(ledgerContract.address, depositAmount); + console.log(`Approve user's amount (tx: ${tx8.hash})...`); await tx8.wait(); + const tx9 = await ledgerContract.connect(signer).deposit(depositAmount); + console.log(`Deposit user's amount (tx: ${tx9.hash})...`); + await tx9.wait(); + if (user.pointType === 1) { const pointType = 1; const nonce = await ledgerContract.nonceOf(user.address); const signature = ContractUtils.signPointType(signer, pointType, nonce); - const tx9 = await ledgerContract.connect(validator1).setPointType(pointType, user.address, signature); - console.log(`Deposit user's amount (tx: ${tx9.hash})...`); - await tx9.wait(); + const tx10 = await ledgerContract.connect(validator1).setPointType(pointType, user.address, signature); + console.log(`Deposit user's amount (tx: ${tx10.hash})...`); + await tx10.wait(); } } } diff --git a/packages/contracts/deploy/data/shops.json b/packages/contracts/deploy/data/shops.json index 0994b5c1..f89852af 100644 --- a/packages/contracts/deploy/data/shops.json +++ b/packages/contracts/deploy/data/shops.json @@ -1,81 +1,81 @@ [ { - "shopId": "F000100", + "shopId": "0xbe96d74202df38fd21462ffcef10dfe0fcbd7caa3947689a3903e8b6b8749fda", + "name": "Shop-0001", "provideWaitTime": 0, "providePercent": "5", - "phone": "08201010000100", "address": "0xafFe745418Ad24c272175e5B58610A8a35e2EcDa", "privateKey": "0xa237d68cbb66fd5f76e7b321156c46882546ad87d662dec8b82703ac31efbf0a" }, { - "shopId": "F000200", + "shopId": "0x5f59d6b480ff5a30044dcd7fe3b28c69b6d0d725ca469d1b685b57dfc1055d7f", + "name": "Shop-0002", "provideWaitTime": 0, "providePercent": "5", - "phone": "08201010000200", "address": "0xD10ADf251463A260242c216c8c7D3e736eBdB398", "privateKey": "0x05152ad8d5b14d3f65539e0e42131bc72cbdd16c486cb215d60b7dc113ca1ebd" }, { - "shopId": "F000300", + "shopId": "0x08f12f827f0521be34e7563948dc778cb80f7498cebb57cb1a62840d96eb143c", + "name": "Shop-0003", "provideWaitTime": 0, "providePercent": "5", - "phone": "08201010000300", "address": "0xD12e250C8F5C3720297CeBF5A50655A8e2348847", "privateKey": "0xf4b8aa615834c57d1e4836c683c8d3460f8ff232667dc317f82844e674ee4f26" }, { - "shopId": "F000400", + "shopId": "0xbefa86be32da60a87a843bf3e63e77092040ee044f854e8d318d1eb18d208f4d", + "name": "Shop-0004", "provideWaitTime": 0, "providePercent": "5", - "phone": "08201010000400", "address": "0x57D5E271FF8A4d49AE793B8b6Cf005E33FA4FA48", "privateKey": "0xe58b3ae0e68a04996d6c13c9f9cb65b2d88ada662f28edd67db8c8e1ef45eed4" }, { - "shopId": "F000500", + "shopId": "0x3ecc54754b835d04ee5b4df7d0d0eb4e0eafc33ac8de4d282d641f7f054d1c27", + "name": "Shop-0005", "provideWaitTime": 0, "providePercent": "5", - "phone": "08201010000500", "address": "0x14De3f38D8deB7fFc5c15859bA05e4B088F8F631", "privateKey": "0x1f2246394971c643d371a2b2ab9176d34b98c0a84a6aa5e4e53f73ab6119dcc1" }, { - "shopId": "F000600", + "shopId": "0x548b7faa282b8721218962e3c1ae43608009534663de91a1548e37cc1c6980a5", + "name": "Shop-000600", "provideWaitTime": 0, "providePercent": "5", - "phone": "08201010000600", "address": "0xA9c5559da87A7511D28e87C751dAfE65374Ce59f", "privateKey": "0x49d28e02787ca6f2827065c83c9c4de2369b4d18d132505d3c01ba35a4558214" }, { - "shopId": "F000700", + "shopId": "0x08bde9ef98803841f22e8bc577a69fc47913914a8f5fa60e016aaa74bc86dd47", + "name": "Shop-0007", "provideWaitTime": 0, "providePercent": "5", - "phone": "08201010000700", "address": "0xAAa610aE6711B810921ca06629c42a3E127851cd", "privateKey": "0xd72fb7fe49fd18f92481cbee186050816631391b4a25d579b7cff7efdf7099d3" }, { - "shopId": "F000800", + "shopId": "0x04ef11be936f49f6388dd20d062e43170fd7ce9e968e51426317e284b9309361", + "name": "Shop-0008", "provideWaitTime": 0, "providePercent": "5", - "phone": "08201010000800", "address": "0x4BbfEd63b19954A357C1Dfc3Ba8820d2eE31Bbcf", "privateKey": "0x90ee852d612e080fb99914d40e0cd75edf928ca895bdda8b91be4b464c55edfc" }, { - "shopId": "F000900", + "shopId": "0x6bad0e0f6ad0fdd7660393b45f452a0eca3f6f1f0eeb25c5902e46a1ffeeef3f", + "name": "Shop-0009", "provideWaitTime": 0, "providePercent": "5", - "phone": "08201010000900", "address": "0xe3812c628b1E0245Eed4A548914e32C9eeFda019", "privateKey": "0x8bfcb398c9cb1c7c11790a2293f6d4d8c0adc5f2bd3620561dd81e2db2e9a83e" }, { - "shopId": "F001000", + "shopId": "0x2a23595cf31762a61502546e8b9f947baf3bd55040d9bd535f8afdbff409fa60", + "name": "Shop-0010", "provideWaitTime": 0, "providePercent": "5", - "phone": "08201010001000", "address": "0xfD8072e4809BFADd90ad6D60aF31C8dCd7a46990", "privateKey": "0x77962b6be5cd2ab0c692fe500f50965b5051822d91fece18dcd256dc79182305" } diff --git a/packages/contracts/deploy/data/users.json b/packages/contracts/deploy/data/users.json index 20e5c0e8..d0289d88 100644 --- a/packages/contracts/deploy/data/users.json +++ b/packages/contracts/deploy/data/users.json @@ -1,700 +1,700 @@ [ { "idx": 0, - "phone":"08201010002000", + "phone": "08201010002000", "address": "0x64D111eA9763c93a003cef491941A011B8df5a49", "privateKey": "0x70438bc3ed02b5e4b76d496625cb7c06d6b7bf4362295b16fdfe91a046d4586c", "pointType": 0 }, { "idx": 1, - "phone":"08201010002001", + "phone": "08201010002001", "address": "0x3FE8D00143bd0eAd2397D48ba0E31E5E1268dBfb", "privateKey": "0x44868157d6d3524beb64c6ae41ee6c879d03c19a357dadb038fefea30e23cbab", "pointType": 0 }, { "idx": 2, - "phone":"08201010002002", + "phone": "08201010002002", "address": "0xCf44157e9df307c90FC7762933Ac1e2921e8b39E", "privateKey": "0x11855bdc610b27e6b98de50715c947dc7acd95166d70d66b773f06b328ee8b5c", "pointType": 0 }, { "idx": 3, - "phone":"08201010002003", + "phone": "08201010002003", "address": "0xf26f7844f5B4770c47f34ea35a03B2b3534d08FE", "privateKey": "0x2e981a3691ff15706d808b457699ddd46fb9ebf8d824295fb585e71e1db3c4c1", "pointType": 0 }, { "idx": 4, - "phone":"08201010002004", + "phone": "08201010002004", "address": "0x7Bac9e662E2C1Cf9f6f97F8CaF9c7aDE8F146bd1", "privateKey": "0xb93f43bdafc9efee5b223735a0dd4efef9522f2db5b9f70889d6fa6fcead50c4", "pointType": 0 }, { "idx": 5, - "phone":"08201010002005", + "phone": "08201010002005", "address": "0x852DB1c83e17BE9fba782c97436F47cE4ad2Af83", "privateKey": "0xcd0050e45b8ed7cf14055a640a129c81c805128a3711dbe5af1c5b434ba2d4cc", "pointType": 0 }, { "idx": 6, - "phone":"08201010002006", + "phone": "08201010002006", "address": "0x5857f28FDFE295bde60967c749199cAfB89C720F", "privateKey": "0x1df07300f5c65983b16d0b28e4fce3def7141cb573df00d077c8a8b12de47be0", "pointType": 0 }, { "idx": 7, - "phone":"08201010002007", + "phone": "08201010002007", "address": "0x98b0fdb6C23C7C80B4728579e76F4aD95fe7014A", "privateKey": "0xd96b986c2d61fa843f856ad621d4343705b296d88e3c96a17c726d130e95118e", "pointType": 0 }, { "idx": 8, - "phone":"08201010002008", + "phone": "08201010002008", "address": "0xF51A41cD49ff9B280Acea3768f8624003C69F3ea", "privateKey": "0x115094e272f33caa245e5458eb0debd7864eb5f71980d508a27612845540ad99", "pointType": 0 }, { "idx": 9, - "phone":"08201010002009", + "phone": "08201010002009", "address": "0x8340Bb9Cd5C3827c213beB23b05E1815c4bE9AFA", "privateKey": "0x5c7744beb5c2a2369f22879eeab289ae6fd2d46c2ff348fcdd5d3c70d846a1a1", "pointType": 0 }, { "idx": 10, - "phone":"08201010002010", + "phone": "08201010002010", "address": "0xf3802b4c177aE5ca5ED022Ced2643dAE79E3b824", "privateKey": "0x46ba360778a00c5bf9322a702bbbd38c7a56f20f9360a14686f5b71834922569", "pointType": 0 }, { "idx": 11, - "phone":"08201010002011", + "phone": "08201010002011", "address": "0x35004290E2890782DE456A8C0787f0747E93089B", "privateKey": "0x6111ebbc274bd07fb2fd53d66652766686e85f21cfdf615f3236e687c7aabfa2", "pointType": 0 }, { "idx": 12, - "phone":"08201010002012", + "phone": "08201010002012", "address": "0xB0ddD72EEB6b692505b99C912c30a5509f4D9062", "privateKey": "0x1642cadf4dc8fc81dfe0c148227836a1c22230846701de1f12db59f031b8067c", "pointType": 0 }, { "idx": 13, - "phone":"08201010002013", + "phone": "08201010002013", "address": "0xAc09cdb210e7F5528e3b045F6726A145d08E25be", "privateKey": "0x86e806c4d2e1224ed91c78af00c3ef328d023db20027d892b05d551bff8ad910", "pointType": 0 }, { "idx": 14, - "phone":"08201010002014", + "phone": "08201010002014", "address": "0xdD30Ef7eefC7ec283d9B573D86e11a77E9b3F722", "privateKey": "0xe7b52d74383c5e1a576b84eb96384627dbb50469fbb91bfa227ddfe250e20a0e", "pointType": 0 }, { "idx": 15, - "phone":"08201010002015", + "phone": "08201010002015", "address": "0xA579D3De3fb6613017A03C5C66d4f1Cf3d37b427", "privateKey": "0xba5ee30d9313800952d3d3f6d367039c22bb09f94ec57e4bccc506f0da1fa552", "pointType": 0 }, { "idx": 16, - "phone":"08201010002016", + "phone": "08201010002016", "address": "0x49760921d14C3343f04Bf46371aD782C1478F5BC", "privateKey": "0xbbadbc87a1dc7cd6f71fbc374bc5ec77b3680dbb3f59074c7c3682fec24c322f", "pointType": 0 }, { "idx": 17, - "phone":"08201010002017", + "phone": "08201010002017", "address": "0x7B7B7Fb2613Dd7286DcAe541bF2391c9754eA3cd", "privateKey": "0xfefd0cb39ecbaebb7b4c19a7288458809a906aed6f001202a3e2cb01a6d4ec23", "pointType": 0 }, { "idx": 18, - "phone":"08201010002018", + "phone": "08201010002018", "address": "0xB4008dDce19b0061317726c5fC3413d8C8C828Eb", "privateKey": "0xc5cfabd6975b0f83bb367df4679da25450be793839d0bbefdc4989f3e2376eec", "pointType": 0 }, { "idx": 19, - "phone":"08201010002019", + "phone": "08201010002019", "address": "0xd1D879664617032Da2Da21CF3DA9e58a487673A9", "privateKey": "0x3d53fea04641879be6a3a8a8d61d4d441eb401d7b3fe352eff9f7ac8ba1a4ec9", "pointType": 0 }, { "idx": 20, - "phone":"08201010002020", + "phone": "08201010002020", "address": "0x71770F1Ed060051ebb6f3f2350418ea339268505", "privateKey": "0x3dc149190a33487e968beaaa4f0cab869e02534b8d9d4c999d306c49ad4696e8", "pointType": 0 }, { "idx": 21, - "phone":"08201010002021", + "phone": "08201010002021", "address": "0x903063cE4dBF5C61bB2f4d697C082Ac3F26c9e03", "privateKey": "0x95c6a667040a653ccd200885b6e67670cc115c29b13b1c2022993d13635a0b31", "pointType": 0 }, { "idx": 22, - "phone":"08201010002022", + "phone": "08201010002022", "address": "0x74B936f54fDbDa9324a871226835944D6468CdBb", "privateKey": "0xae5817e4a2ea1371cfd4d35ec5ba155585d3cebe18e6197bc4e030bc0e3dd9f8", "pointType": 0 }, { "idx": 23, - "phone":"08201010002023", + "phone": "08201010002023", "address": "0xA6543b00acde8F61475B089474EDdE92223103A5", "privateKey": "0x32990d3f18c3625901d5254f517daa5ef1c43383027a3b98902f5ebf9cb5a692", "pointType": 0 }, { "idx": 24, - "phone":"08201010002024", + "phone": "08201010002024", "address": "0xa8201943223834BaB8e4C877971568e8daf4963F", "privateKey": "0x6b4d24d4809dad462f6ca8ff1fb71b64091d0ff11c3ebc548c6cddd01dfc8c0f", "pointType": 0 }, { "idx": 25, - "phone":"08201010002025", + "phone": "08201010002025", "address": "0xBE43a4598aB331D60054726037F942a432E2b0FA", "privateKey": "0x98b748b35f47c3498271e1b5f8da35b40670214a775ca0f07b27780ab8135ab1", "pointType": 0 }, { "idx": 26, - "phone":"08201010002026", + "phone": "08201010002026", "address": "0x096710E3B5ccAb0a35501226f7D00B57b41901F3", "privateKey": "0x9cfb97b7abe04557a83cf19611b5ec6e674ca3fe5dffe37ed047a0fe9892fb9c", "pointType": 0 }, { "idx": 27, - "phone":"08201010002027", + "phone": "08201010002027", "address": "0x06796CE510010e90F519e9cBE28E5075c7e80Ba8", "privateKey": "0x3085e5b217e027e094822aa171445f971fbd5aec14b1ae1cdc8ac759af24472d", "pointType": 0 }, { "idx": 28, - "phone":"08201010002028", + "phone": "08201010002028", "address": "0x4aCB655Ec9cb9b7bA53059D2754Da628F97E5520", "privateKey": "0x63015d622dac9ea25bca0749eca67698d78ee22c29bd4536e000d65325600cec", "pointType": 0 }, { "idx": 29, - "phone":"08201010002029", + "phone": "08201010002029", "address": "0x58cd45F5461DFa1c03e44459f700Aa530488Fe7f", "privateKey": "0xe9edb4354287e55d123672088c9c6b55ead2859b3b577d02f6fd33c7a99e3164", "pointType": 0 }, { "idx": 30, - "phone":"08201010002030", + "phone": "08201010002030", "address": "0xcD2803008856100264F17140d4d977768C36B546", "privateKey": "0x678daaa72339201608534313be62c7d3835c7baa1dc588ebcb1eb865385ca54e", "pointType": 0 }, { "idx": 31, - "phone":"08201010002031", + "phone": "08201010002031", "address": "0x8f05bddf379d89c827bAEFE43a5eca3aBE2CAf49", "privateKey": "0xf02e9bf477c21e05b60de4e8a65824d9aae194eccd193245a6296c13dc675227", "pointType": 0 }, { "idx": 32, - "phone":"08201010002032", + "phone": "08201010002032", "address": "0x7c86E333501Ac8BfA7b5a4A9a166922d1872FeBa", "privateKey": "0xb30667148df49d3ffe8e62e72df69358e286f4db5f487c5699dd3ca545a495cf", "pointType": 0 }, { "idx": 33, - "phone":"08201010002033", + "phone": "08201010002033", "address": "0x809d7F5B2AC27Fc3aBc8441EC31386a80EdA1592", "privateKey": "0x9f09e74e517af6f604b4cf5d7061fe2736638b7b81809e06fb1cb1e10b23a58b", "pointType": 0 }, { "idx": 34, - "phone":"08201010002034", + "phone": "08201010002034", "address": "0x7642b1EC5175CC389a62632E0AF253Cf78bb07b9", "privateKey": "0x843bc9928bc75cbd1296264813b5e125f32497eae208a2c1d4ea6532a9e52490", "pointType": 0 }, { "idx": 35, - "phone":"08201010002035", + "phone": "08201010002035", "address": "0x2Fe00A97b2e578bF7381CFA0379d3756372fF644", "privateKey": "0x756d1ba4c61888a602cbfb75ee54ebeb9af22d75834522779bc24c0661242185", "pointType": 0 }, { "idx": 36, - "phone":"08201010002036", + "phone": "08201010002036", "address": "0x265A22e880fD793e277625ea8e4f7D58D40C419F", "privateKey": "0xee5731e8b4ce2464e41990b6a4ce826cc61a9813d0ce4d7e1ec553f4961502e1", "pointType": 0 }, { "idx": 37, - "phone":"08201010002037", + "phone": "08201010002037", "address": "0x89e3b2D91ecaf08016eEDb966c1fecA1e326714e", "privateKey": "0x329357385b1a8ee0425ec907e52916a384cb991d76d1e595a619c9b6957d080c", "pointType": 0 }, { "idx": 38, - "phone":"08201010002038", + "phone": "08201010002038", "address": "0x2c620BdACb2ef5f7AE80Ca323f81158845A1605e", "privateKey": "0x3432e4b1caec0d0733307e427e10b2732b1c1a70af331a3c08ae47a47312d6be", "pointType": 0 }, { "idx": 39, - "phone":"08201010002039", + "phone": "08201010002039", "address": "0x7CDaDf72FDbE02641027ACD0Aa517D3cA76996eF", "privateKey": "0x91388010aa90bf0200a6e39dee390fd5a2f5db12a50571c83a0ef16f91a40b7e", "pointType": 0 }, { "idx": 40, - "phone":"08201010002040", + "phone": "08201010002040", "address": "0xb92E3679F3DA94003063FCf72E525bC7Df99bA3C", "privateKey": "0xb55231ba7970293f5a8ee4452ebf937d1f3d5f64885bd713f228786f87708de3", "pointType": 0 }, { "idx": 41, - "phone":"08201010002041", + "phone": "08201010002041", "address": "0x8cD7f4FD8ADd776B28D6A6A61625a89b1738c8d1", "privateKey": "0xb25642f78c06f5b6cb145f00724e8ee7ee4f6f7a36d801b2605ce73ca88833e0", "pointType": 0 }, { "idx": 42, - "phone":"08201010002042", + "phone": "08201010002042", "address": "0xdCdb0368728F93c3a7aAef38980B5f0933cCcF31", "privateKey": "0x4f8835465e067ecb63035db49651ec195708761ff751815dbed1c232fb4235d4", "pointType": 0 }, { "idx": 43, - "phone":"08201010002043", + "phone": "08201010002043", "address": "0x58F2660975Ac5a747e2D3944AA4649EE460fB26D", "privateKey": "0x8ecdc67a86bfb5be8e2fdd789977df32b0a8c70eefa7406a9701141232533f66", "pointType": 0 }, { "idx": 44, - "phone":"08201010002044", + "phone": "08201010002044", "address": "0xA432821b87110a36f4163E1c5f66185efCB69117", "privateKey": "0xe82958390a9e9706370f550cbda28f6a273faf835be363ec45ab99ed68039797", "pointType": 0 }, { "idx": 45, - "phone":"08201010002045", + "phone": "08201010002045", "address": "0x2122bf35f2D64E64483A4289cD0Bcd613b1bcAFa", "privateKey": "0x5757a560ba6caabe98b77c04b77ad61eae34776b9613f698d15edef1e30ce95c", "pointType": 0 }, { "idx": 46, - "phone":"08201010002046", + "phone": "08201010002046", "address": "0xD303166E007f601cfAB726C8d078BE75e7fE809a", "privateKey": "0xbb97770147c281103a36b1ce9720307e98ed74dd69eb7a87eceb25df9b1f42ea", "pointType": 0 }, { "idx": 47, - "phone":"08201010002047", + "phone": "08201010002047", "address": "0x94c0Cd28e2988f58388E709eB2010c721e5c32E2", "privateKey": "0x1b8eb15d5010a6673963207683fba7d5875a8aeb9d8c265351bb3934ca99bfcb", "pointType": 0 }, { "idx": 48, - "phone":"08201010002048", + "phone": "08201010002048", "address": "0xDF32A6dD8993528135C2e13B18dDAD3f78c581cF", "privateKey": "0xeb50af73ef5b4cf3fc30dbd2334bd10ca285e266eb160990a21811087b144c4a", "pointType": 0 }, { "idx": 49, - "phone":"08201010002049", + "phone": "08201010002049", "address": "0xFF94F0D95F4130A7212C5D91850373D5Fe9eeAF7", "privateKey": "0xa158fa18c8109cc560fa76d8fbc29017a312924de0eea58db085e5f241afce5a", "pointType": 0 }, { "idx": 50, - "phone":"08201010002050", + "phone": "08201010002050", "address": "0x90Ab97F65F1A5d02320e887fd07066c3e78c5846", "privateKey": "0x833bfa4afbb90959863ab74a856a0714bf1c8a0fccb7a1c3fe919a1aca2938d2", "pointType": 1 }, { "idx": 51, - "phone":"08201010002051", + "phone": "08201010002051", "address": "0x14C17C2286324Db12A47bab0477D100dabB92b82", "privateKey": "0x913d15c13b4719152f419249d629172c84c48b4129d65a8dbd81c96d65ab9877", "pointType": 1 }, { "idx": 52, - "phone":"08201010002052", + "phone": "08201010002052", "address": "0xB2E1578C22c1d918706EC6314a15678ccD9D918C", "privateKey": "0xd62d89ded73ef4fa38a339608f196019cdcd60e5f19e9adea5456685b691b6c9", "pointType": 1 }, { "idx": 53, - "phone":"08201010002053", + "phone": "08201010002053", "address": "0xc3b44fA9c5eF71c8e4D2C7d71E46aa5306a24f18", "privateKey": "0xad02f8ffb2bcb3c6d2c1bbc67e90e24697c12bdb57416e91386f2b40582c0d6a", "pointType": 1 }, { "idx": 54, - "phone":"08201010002054", + "phone": "08201010002054", "address": "0xBADDa09A6543EF1c9dAcaF1B9f556683aA07Df17", "privateKey": "0x3a9e72cfca22ca74267d2b8b8373535bba25af595b94244c04d83ba0a5192c70", "pointType": 1 }, { "idx": 55, - "phone":"08201010002055", + "phone": "08201010002055", "address": "0xbAC552C9638a004642C539af7c730DF3cA78835d", "privateKey": "0x77768416b1d1b6f1d27c74e9f0579f114b4e7cecfd9633dc6ecf635b75df4e4f", "pointType": 1 }, { "idx": 56, - "phone":"08201010002056", + "phone": "08201010002056", "address": "0x821438f750867b0c4cB0F4C96f95c21b263238DE", "privateKey": "0x2603bcac3316baa54a4c522381c133a5561ddd75a093a400250b71a3e17c4036", "pointType": 1 }, { "idx": 57, - "phone":"08201010002057", + "phone": "08201010002057", "address": "0x3fD2AF3AC475B764F2d94F52fA48135b2E71E3b6", "privateKey": "0xc5a59d32c076b0982199736fd31f36fbc9ddb2aae94c4434415e7ea470065b32", "pointType": 1 }, { "idx": 58, - "phone":"08201010002058", + "phone": "08201010002058", "address": "0x65738d6AfD0eac08B0375A628bFc96BF4e6F5E4B", "privateKey": "0x95aec98dc6e55b8d96bb1c6359851efb64bc1ba2ec52575898e57d296beceb2d", "pointType": 1 }, { "idx": 59, - "phone":"08201010002059", + "phone": "08201010002059", "address": "0x366Ec0bA6e9A28ef6CBE4Ddb900028336F67b32f", "privateKey": "0xf904d7431d9752b14f632c5a75fabfa555202a651394a441b3a832c17749c4f6", "pointType": 1 }, { "idx": 60, - "phone":"08201010002060", + "phone": "08201010002060", "address": "0x967614054b6906B39d449f53C0d8A7A3F4e50584", "privateKey": "0x901216b17bfa65f762889ed7d074139543c3930205af32ff1820c18d42d2699b", "pointType": 1 }, { "idx": 61, - "phone":"08201010002061", + "phone": "08201010002061", "address": "0xB09353ABE11E1F5e6Bff8cD7743322d30D9dE44E", "privateKey": "0xa284e364aa4210727f365bdb79388d6ba52c90881152791dfe81ae4db52be843", "pointType": 1 }, { "idx": 62, - "phone":"08201010002062", + "phone": "08201010002062", "address": "0x19594858cE5cC77bF1ff71B61214D41e0d5a1aE8", "privateKey": "0x91cbdcc1cc6e0e0c6114de4b7e3cff89b48386e00993609f370adee3039d6678", "pointType": 1 }, { "idx": 63, - "phone":"08201010002063", + "phone": "08201010002063", "address": "0xfaBC045A3d34A070dc0a4e34d916CBf1Febed8e5", "privateKey": "0xd3ab09578476303325cd01befe8c2345dcb72f2ef11b025fedf754adb8bd7acf", "pointType": 1 }, { "idx": 64, - "phone":"08201010002064", + "phone": "08201010002064", "address": "0x7De5c9cE240bdeb4B35E742BEec3f81b9657c724", "privateKey": "0xfdb7e230a1c2e179281316c3c9bd26deba5cc49a470f2e81628e484bb1e9b135", "pointType": 1 }, { "idx": 65, - "phone":"08201010002065", + "phone": "08201010002065", "address": "0xAfCA35269d937662Bf2b27a2299aeEB0FB42Ea17", "privateKey": "0xdf2448abc706f7f1fbfd677e94560b31133b151bc56b3845a114d7dc6c67a25f", "pointType": 1 }, { "idx": 66, - "phone":"08201010002066", + "phone": "08201010002066", "address": "0x35aCaF5bD718349620545ec339B168B23d1A3dcd", "privateKey": "0xa2d27c16136206ad1363f00c247a5594410caf7be25056ed1ef3f83f5d15e615", "pointType": 1 }, { "idx": 67, - "phone":"08201010002067", + "phone": "08201010002067", "address": "0x4324Fb178B841a436c18F3191BFa75026d4112B2", "privateKey": "0x923774230aa5b69c24a9a2631c1f6c3a701a840d0834e607950207df7753ed6e", "pointType": 1 }, { "idx": 68, - "phone":"08201010002068", + "phone": "08201010002068", "address": "0xC9c29fD8fF7204965bdE443cd4ca4c35B451B19e", "privateKey": "0xb74eb215de25217bdc80472039609bab275890d7e1b2a491fae1b479f523c26e", "pointType": 1 }, { "idx": 69, - "phone":"08201010002069", + "phone": "08201010002069", "address": "0x42c7E54a2CB757F121180Be68bc1b5fd9Db1c8f5", "privateKey": "0x305d6202a3edbb6c6bed32bb2544f593cf30df96ba3e5e6aa38a26c53031e043", "pointType": 1 }, { "idx": 70, - "phone":"08201010002070", + "phone": "08201010002070", "address": "0xAC7Fe12CeDA522Bf1cb0D3A30272C3A3E7FE177f", "privateKey": "0x71b20d76ed966d6a7860de9ec2f99b24d1f1f4365449c0af831b8adba609b20c", "pointType": 1 }, { "idx": 71, - "phone":"08201010002071", + "phone": "08201010002071", "address": "0xa1E4b09110181051585B990d7024397FE6370346", "privateKey": "0xaf898e887fd169a7c75b2b0587f7e32a97ce05016da7765d84a9b026197be91c", "pointType": 1 }, { "idx": 72, - "phone":"08201010002072", + "phone": "08201010002072", "address": "0xcB41a82601703A3EDe0fc30d994ad43888F7c511", "privateKey": "0x48d78d317df2e314c16ae80f7ca29b874b12e0610e5c1d7fa772040ebd4485d9", "pointType": 1 }, { "idx": 73, - "phone":"08201010002073", + "phone": "08201010002073", "address": "0x8e88b88C3BbA79E9E5897bC8D6d8bEf1CAc64f56", "privateKey": "0x01a265e82414c165bd555fd0e45ac14448ea622948c9f9015daedd1faa3987b5", "pointType": 1 }, { "idx": 74, - "phone":"08201010002074", + "phone": "08201010002074", "address": "0x010e3d8c7fec02ce7fA7288D11f1f6C1400FE07A", "privateKey": "0xf2bee079f06cb18fe95abece2f219f692d96d34239e7816d735b96085447f704", "pointType": 1 }, { "idx": 75, - "phone":"08201010002075", + "phone": "08201010002075", "address": "0xb2b5868f995F88293011D10e87ae0e9E979b1F16", "privateKey": "0x0e35e09cc63f3da830011d68835231eb57e80c0780dd0aa4ca9caa4d40b7d560", "pointType": 1 }, { "idx": 76, - "phone":"08201010002076", + "phone": "08201010002076", "address": "0xD391edCddbc48410cC66D022932FDd517f38172B", "privateKey": "0xd0477924d13dae8529ee89c0e85f49da8e373f0caf8d2de4f2af92f3227476e3", "pointType": 1 }, { "idx": 77, - "phone":"08201010002077", + "phone": "08201010002077", "address": "0x6a03061a10C3E39B59082c01d06ca48fc5257B36", "privateKey": "0x8eed3c9bff85c168d1f533dbff2f41bd016900dc0ba40880b3d868021740bce9", "pointType": 1 }, { "idx": 78, - "phone":"08201010002078", + "phone": "08201010002078", "address": "0xEe27eEb9D8b7De85CCF13C953a94f59bd9bbaA92", "privateKey": "0xd9b2e116241042f3032a126eba7f110ad5d91aef895fd531b228960bedf67073", "pointType": 1 }, { "idx": 79, - "phone":"08201010002079", + "phone": "08201010002079", "address": "0xdb757A91b920Cc3AC04F04fc7905F13c4352908d", "privateKey": "0x9b1de659ea30e46aac17f19002c3e22c7f39071cfc63eab6338a3dd4c33f20d9", "pointType": 1 }, { "idx": 80, - "phone":"08201010002080", + "phone": "08201010002080", "address": "0xc41Ae4077732ca2F35745674A8ea60CC3Daca6cB", "privateKey": "0x0f1975d466a30e1d5e765de51b890dd52aa6b96ebcd485b1c4a8ee9326ba7c2b", "pointType": 1 }, { "idx": 81, - "phone":"08201010002081", + "phone": "08201010002081", "address": "0x8d6433eE1105a14cB357739474da40a263bb1b6b", "privateKey": "0x7eadce18a65a9e28644c92b852050e8d758e22fdd93be712893f5fc58d46da9e", "pointType": 1 }, { "idx": 82, - "phone":"08201010002082", + "phone": "08201010002082", "address": "0xf062aa80Dec9c82f7116B1da4438966AC1C746C2", "privateKey": "0xdf0cea945d22364a723dc35bed386a2a86281b9be854feac39e96eebad101453", "pointType": 1 }, { "idx": 83, - "phone":"08201010002083", + "phone": "08201010002083", "address": "0x7fda36C554872bE7Fe2b94F07125496Cb755dA6A", "privateKey": "0x7f64538fb204c0cbb6395a42f23157ef794a49f309c37f721080a5292ed99fab", "pointType": 1 }, { "idx": 84, - "phone":"08201010002084", + "phone": "08201010002084", "address": "0xc47949A63Ed9E163dcBb84443c3FE6702D12a1Ed", "privateKey": "0xcbbafe4ee975942df434fb15b46f313c30f8815477c569cdae4217ddb2a47c1e", "pointType": 1 }, { "idx": 85, - "phone":"08201010002085", + "phone": "08201010002085", "address": "0x3BF101CcA175ebD8a2f475784b59A1f197c4EB87", "privateKey": "0xdb1c949bcd0443ef0e84446bb32b65dca0cd28a07f8a589152623acbeee1be2e", "pointType": 1 }, { "idx": 86, - "phone":"08201010002086", + "phone": "08201010002086", "address": "0x62B811293e809BFc5D1177CCdf0DD8D18C871caA", "privateKey": "0x7b7c89d8a1fc0bd565942c881c153153783d8c8b763816f28ecd4ed1abf57f37", "pointType": 1 }, { "idx": 87, - "phone":"08201010002087", + "phone": "08201010002087", "address": "0x6F7C263aBe2b734ec520166Ecae6C34DD0B7AeEF", "privateKey": "0xa077c86f216fddae34c3d7d954ac03d0945c501e5a8e0018f9f40affd5503b1a", "pointType": 1 }, { "idx": 88, - "phone":"08201010002088", + "phone": "08201010002088", "address": "0x5BD8556a379438B7761dAEe893d33afDA63DdE66", "privateKey": "0x5a90605d881b5535a8bad62f14f50b1a37fea8f20ef85991b0ad783b9cce1a03", "pointType": 1 }, { "idx": 89, - "phone":"08201010002089", + "phone": "08201010002089", "address": "0xeF70Cbb5Bcdb4D8597c1958572875075FaC935aa", "privateKey": "0xdbaea97fa43c58a47b87dd8c6b6f6dabb663dbbadf6f992e765034227c993cb3", "pointType": 1 }, { "idx": 90, - "phone":"08201010002090", + "phone": "08201010002090", "address": "0x3Cc670905d684A19D7318CE02b36183b680aC9Ba", "privateKey": "0xf9e277ac480ac14c04dd1cfd99b340b4c9d485b3116157ef5d2ac8f396c7285d", "pointType": 1 }, { "idx": 91, - "phone":"08201010002091", + "phone": "08201010002091", "address": "0x4f84af3DAe0dff52851Bc51D05579Ce31CB4aA41", "privateKey": "0x696fb1e2444217e7be398c3dbe096a115e6202f4e2fa7ae2c8a220e64f939029", "pointType": 1 }, { "idx": 92, - "phone":"08201010002092", + "phone": "08201010002092", "address": "0x1A976a73C2E1d578d12C1d5490EA39Da032DED09", "privateKey": "0x163776f9e9f1a96c971ba998ba9db13a621f6b5bef56ed37544e102a004e93cf", "pointType": 1 }, { "idx": 93, - "phone":"08201010002093", + "phone": "08201010002093", "address": "0x274b22DA330f2888CA272b325E4B806BEE1020dD", "privateKey": "0x0faf1b2426d64b103aaf827ef79331838b486cd43b50c37b890c02be90245846", "pointType": 1 }, { "idx": 94, - "phone":"08201010002094", + "phone": "08201010002094", "address": "0xC6E444e95F5c0e1D08bD6BF696e7b7be78C52F0A", "privateKey": "0x3b5e7e810c6908d7629a3425252d3a4350b0c4c7ecdc4b070dc390c7a14d7ee3", "pointType": 1 }, { "idx": 95, - "phone":"08201010002095", + "phone": "08201010002095", "address": "0xBf71BE43744dE11ab907Cd437a3544988Bcd64E9", "privateKey": "0x40036472b731d1a288b47c7182b988d540bc63c32f1e362210d4c074c9e609bb", "pointType": 1 }, { "idx": 96, - "phone":"08201010002096", + "phone": "08201010002096", "address": "0x8FF6E213BF89DBad2ff139E3C9D07D66438c8cC0", "privateKey": "0x9aa24c5b22cddbe10ba0e587f9cf691490250e7b9168faa87c9c482abe8f10de", "pointType": 1 }, { "idx": 97, - "phone":"08201010002097", + "phone": "08201010002097", "address": "0x9CB046D582f5aF26e649e4657953523de0b5177A", "privateKey": "0x60e8ebd2860037d34b3afd6122235afdfd34d32950e1adc70e98b73ea1ba181b", "pointType": 1 }, { "idx": 98, - "phone":"08201010002098", + "phone": "08201010002098", "address": "0x24dd2E8A8571090fDA4D92a9d94995E651B65640", "privateKey": "0x7d3255042d6b870964d1a33b724cc9af9b3d8fa9e3572cec3046dd670e57f4e4", "pointType": 1 }, { "idx": 99, - "phone":"08201010002099", + "phone": "08201010002099", "address": "0x20eB9941Df5b95b1b1AfAc1193c6a075B6191563", "privateKey": "0x16541efcf7b3743f7d174d3daaa88ed32fdb2ba5495710e4859a34d00df29144", "pointType": 1 diff --git a/packages/contracts/npm/artifacts.ts b/packages/contracts/npm/artifacts.ts index c846f189..9f1254b7 100644 --- a/packages/contracts/npm/artifacts.ts +++ b/packages/contracts/npm/artifacts.ts @@ -1,20 +1,15 @@ // JSON artifacts of the contracts -import * as EmailLinkCollection from "../artifacts/del-osx-artifacts/contracts/EmailLinkCollection.sol/EmailLinkCollection.json"; -import * as PhoneLinkCollection from "../artifacts/del-osx-artifacts/contracts/PhoneLinkCollection.sol/PhoneLinkCollection.json"; - +import * as CurrencyRate from "../artifacts/contracts/CurrencyRate.sol/CurrencyRate.json"; import * as Ledger from "../artifacts/contracts/Ledger.sol/Ledger.json"; import * as ShopCollection from "../artifacts/contracts/ShopCollection.sol/ShopCollection.json"; import * as Token from "../artifacts/contracts/Token.sol/Token.json"; -import * as TokenPrice from "../artifacts/contracts/TokenPrice.sol/TokenPrice.json"; import * as ValidatorCollection from "../artifacts/contracts/ValidatorCollection.sol/ValidatorCollection.json"; export default { - EmailLinkCollection, - PhoneLinkCollection, ShopCollection, Ledger, Token, - TokenPrice, + CurrencyRate, ValidatorCollection, }; diff --git a/packages/contracts/src/utils/ContractUtils.ts b/packages/contracts/src/utils/ContractUtils.ts index 3d3a4cfd..eba3683a 100644 --- a/packages/contracts/src/utils/ContractUtils.ts +++ b/packages/contracts/src/utils/ContractUtils.ts @@ -102,7 +102,7 @@ export class ContractUtils { nonce: BigNumberish ): Uint8Array { const encodedResult = hre.ethers.utils.defaultAbiCoder.encode( - ["string", "uint256", "string", "string", "address", "uint256"], + ["string", "uint256", "string", "bytes32", "address", "uint256"], [purchaseId, amount, currency, shopId, address, nonce] ); return arrayify(hre.ethers.utils.keccak256(encodedResult)); @@ -152,4 +152,12 @@ export class ContractUtils { const message = ContractUtils.getPointTypeMessage(type, await signer.getAddress(), nonce); return signer.signMessage(message); } + + public static getShopId(name: string, account: string): string { + const encodedResult = hre.ethers.utils.defaultAbiCoder.encode( + ["string", "address", "bytes32"], + [name, account, crypto.randomBytes(32)] + ); + return hre.ethers.utils.keccak256(encodedResult); + } } diff --git a/packages/contracts/test/02-ShopCollection.test.ts b/packages/contracts/test/02-ShopCollection.test.ts index d30f00cf..5fd11c1d 100644 --- a/packages/contracts/test/02-ShopCollection.test.ts +++ b/packages/contracts/test/02-ShopCollection.test.ts @@ -1,6 +1,6 @@ import { Amount } from "../src/utils/Amount"; import { ContractUtils } from "../src/utils/ContractUtils"; -import { ShopCollection, Token, ValidatorCollection } from "../typechain-types"; +import { ShopCollection } from "../typechain-types"; import "@nomiclabs/hardhat-ethers"; import "@nomiclabs/hardhat-waffle"; @@ -11,6 +11,8 @@ import { solidity } from "ethereum-waffle"; import * as hre from "hardhat"; +import { Wallet } from "ethers"; + chai.use(solidity); describe("Test for ShopCollection", () => { @@ -18,46 +20,12 @@ describe("Test for ShopCollection", () => { const [deployer, validator1, validator2, validator3, user1, shop1, shop2, shop3, shop4, shop5] = provider.getWallets(); - const validators = [validator1, validator2, validator3]; - const shopWallets = [shop1, shop2, shop3, shop4, shop5]; - let validatorContract: ValidatorCollection; - let tokenContract: Token; + const shopWallets: Wallet[] = [shop1, shop2, shop3, shop4, shop5]; let shopCollection: ShopCollection; - const amount = Amount.make(20_000, 18); - before(async () => { - const tokenFactory = await hre.ethers.getContractFactory("Token"); - tokenContract = (await tokenFactory.connect(deployer).deploy(deployer.address, "Sample", "SAM")) as Token; - await tokenContract.deployed(); - await tokenContract.deployTransaction.wait(); - for (const elem of validators) { - await tokenContract.connect(deployer).transfer(elem.address, amount.value); - } - - const validatorFactory = await hre.ethers.getContractFactory("ValidatorCollection"); - validatorContract = (await validatorFactory.connect(deployer).deploy( - tokenContract.address, - validators.map((m) => m.address) - )) as ValidatorCollection; - await validatorContract.deployed(); - await validatorContract.deployTransaction.wait(); - - for (const elem of validators) { - await tokenContract.connect(elem).approve(validatorContract.address, amount.value); - await expect(validatorContract.connect(elem).deposit(amount.value)) - .to.emit(validatorContract, "DepositedForValidator") - .withArgs(elem.address, amount.value, amount.value); - const item = await validatorContract.validatorOf(elem.address); - assert.deepStrictEqual(item.validator, elem.address); - assert.deepStrictEqual(item.status, 1); - assert.deepStrictEqual(item.balance, amount.value); - } - const shopCollectionFactory = await hre.ethers.getContractFactory("ShopCollection"); - shopCollection = (await shopCollectionFactory - .connect(deployer) - .deploy(validatorContract.address)) as ShopCollection; + shopCollection = (await shopCollectionFactory.connect(deployer).deploy()) as ShopCollection; await shopCollection.deployed(); await shopCollection.deployTransaction.wait(); }); @@ -65,75 +33,117 @@ describe("Test for ShopCollection", () => { context("Add", () => { interface IShopData { shopId: string; + name: string; provideWaitTime: number; providePercent: number; - phone: string; - account: string; + wallet: Wallet; } const shopData: IShopData[] = [ { - shopId: "F000100", + shopId: "", + name: "Shop 1-1", + provideWaitTime: 0, + providePercent: 5, + wallet: shopWallets[0], + }, + { + shopId: "", + name: "Shop 1-2", + provideWaitTime: 0, + providePercent: 5, + wallet: shopWallets[0], + }, + { + shopId: "", + name: "Shop 2-1", provideWaitTime: 0, providePercent: 5, - phone: "08201020001000", - account: shopWallets[0].address, + wallet: shopWallets[1], }, { - shopId: "F000200", + shopId: "", + name: "Shop 2-2", provideWaitTime: 0, providePercent: 5, - phone: "08201020001001", - account: shopWallets[1].address, + wallet: shopWallets[1], }, { - shopId: "F000300", + shopId: "", + name: "Shop 3", provideWaitTime: 0, providePercent: 5, - phone: "08201020001002", - account: shopWallets[2].address, + wallet: shopWallets[2], }, { - shopId: "F000400", + shopId: "", + name: "Shop 4", provideWaitTime: 0, providePercent: 5, - phone: "08201020001003", - account: shopWallets[3].address, + wallet: shopWallets[3], }, { - shopId: "F000500", + shopId: "", + name: "Shop 5", provideWaitTime: 0, providePercent: 5, - phone: "08201020001004", - account: shopWallets[4].address, + wallet: shopWallets[4], }, ]; - it("Not validator", async () => { - await expect( - shopCollection - .connect(user1) - .add( - shopData[0].shopId, - shopData[0].provideWaitTime, - shopData[0].providePercent, - shopData[0].account - ) - ).to.revertedWith("Not validator"); - }); + for (const elem of shopData) { + elem.shopId = ContractUtils.getShopId(elem.name, elem.wallet.address); + } it("Success", async () => { for (const elem of shopData) { - const phoneHash = ContractUtils.getPhoneHash(elem.phone); await expect( shopCollection - .connect(validator1) - .add(elem.shopId, elem.provideWaitTime, elem.providePercent, elem.account) + .connect(elem.wallet) + .add(elem.shopId, elem.name, elem.provideWaitTime, elem.providePercent) ) .to.emit(shopCollection, "AddedShop") - .withArgs(elem.shopId, elem.provideWaitTime, elem.providePercent, elem.account); + .withNamedArgs({ + shopId: elem.shopId, + name: elem.name, + provideWaitTime: elem.provideWaitTime, + providePercent: elem.providePercent, + account: elem.wallet.address, + }); } expect(await shopCollection.shopsLength()).to.equal(shopData.length); }); + + it("Check", async () => { + const ids = await shopCollection.shopsOf(shopWallets[0].address); + expect(ids).to.deep.equal([shopData[0].shopId, shopData[1].shopId]); + }); + + it("Update", async () => { + const elem = shopData[0]; + await expect(shopCollection.connect(elem.wallet).update(elem.shopId, "New Shop", 86400 * 7, 10)) + .to.emit(shopCollection, "UpdatedShop") + .withNamedArgs({ + shopId: elem.shopId, + name: "New Shop", + provideWaitTime: 86400 * 7, + providePercent: 10, + account: elem.wallet.address, + }); + }); + + it("Remove", async () => { + const elem = shopData[0]; + await expect(shopCollection.connect(elem.wallet).remove(elem.shopId)) + .to.emit(shopCollection, "RemovedShop") + .withNamedArgs({ + shopId: elem.shopId, + }); + }); + + it("Check remove", async () => { + const ids = await shopCollection.shopsOf(shopWallets[0].address); + expect(ids).to.deep.equal([shopData[1].shopId]); + }); }); }); diff --git a/packages/contracts/test/03-Ledger.test.ts b/packages/contracts/test/03-Ledger.test.ts index deb385d8..1f0bbd71 100644 --- a/packages/contracts/test/03-Ledger.test.ts +++ b/packages/contracts/test/03-Ledger.test.ts @@ -16,7 +16,7 @@ import assert from "assert"; import chai, { expect } from "chai"; import { solidity } from "ethereum-waffle"; -import { BigNumber } from "ethers"; +import { BigNumber, Wallet } from "ethers"; import * as hre from "hardhat"; import { AddressZero } from "@ethersproject/constants"; @@ -35,10 +35,10 @@ interface IPurchaseData { interface IShopData { shopId: string; + name: string; provideWaitTime: number; providePercent: number; - phone: string; - account: string; + wallet: Wallet; } interface IUserData { @@ -149,12 +149,11 @@ describe("Test for Ledger", () => { const deployShopCollection = async () => { const shopCollectionFactory = await hre.ethers.getContractFactory("ShopCollection"); - shopCollection = (await shopCollectionFactory - .connect(deployer) - .deploy(validatorContract.address)) as ShopCollection; + shopCollection = (await shopCollectionFactory.connect(deployer).deploy()) as ShopCollection; await shopCollection.deployed(); await shopCollection.deployTransaction.wait(); }; + const deployLedger = async () => { const ledgerFactory = await hre.ethers.getContractFactory("Ledger"); ledgerContract = (await ledgerFactory @@ -186,7 +185,6 @@ describe("Test for Ledger", () => { }; let requestId: string; - /* context("Save Purchase Data & Pay (point, token)", () => { const userData: IUserData[] = [ { @@ -266,49 +264,55 @@ describe("Test for Ledger", () => { const shopData: IShopData[] = [ { - shopId: "F000100", + shopId: "", + name: "Shop1", provideWaitTime: 0, providePercent: 5, - phone: "08201020001000", - account: shopWallets[0].address, + wallet: shopWallets[0], }, { - shopId: "F000200", + shopId: "", + name: "Shop2", provideWaitTime: 0, providePercent: 6, - phone: "08201020001001", - account: shopWallets[1].address, + wallet: shopWallets[1], }, { - shopId: "F000300", + shopId: "", + name: "Shop3", provideWaitTime: 0, providePercent: 7, - phone: "08201020001002", - account: shopWallets[2].address, + wallet: shopWallets[2], }, { - shopId: "F000400", + shopId: "", + name: "Shop4", provideWaitTime: 0, providePercent: 8, - phone: "08201020001003", - account: shopWallets[3].address, + wallet: shopWallets[3], }, { - shopId: "F000500", + shopId: "", + name: "Shop5", provideWaitTime: 0, providePercent: 9, - phone: "08201020001004", - account: shopWallets[4].address, + wallet: shopWallets[4], }, { - shopId: "F000600", + shopId: "", + name: "Shop6", provideWaitTime: 0, providePercent: 10, - phone: "08201020001005", - account: shopWallets[5].address, + wallet: shopWallets[5], }, ]; + before("Set Shop ID", async () => { + for (const elem of shopData) { + elem.shopId = ContractUtils.getShopId(elem.name, elem.wallet.address); + } + }); + before("Deploy", async () => { await deployAllContract(); }); @@ -318,11 +322,17 @@ describe("Test for Ledger", () => { for (const elem of shopData) { await expect( shopCollection - .connect(validator1) - .add(elem.shopId, elem.provideWaitTime, elem.providePercent, elem.account) + .connect(elem.wallet) + .add(elem.shopId, elem.name, elem.provideWaitTime, elem.providePercent) ) .to.emit(shopCollection, "AddedShop") - .withArgs(elem.shopId, elem.provideWaitTime, elem.providePercent, elem.account); + .withNamedArgs({ + shopId: elem.shopId, + name: elem.name, + provideWaitTime: elem.provideWaitTime, + providePercent: elem.providePercent, + account: elem.wallet.address, + }); } expect(await shopCollection.shopsLength()).to.equal(shopData.length); }); @@ -1174,49 +1184,55 @@ describe("Test for Ledger", () => { const shopData: IShopData[] = [ { - shopId: "F000100", + shopId: "", + name: "Shop1", provideWaitTime: 0, providePercent: 5, - phone: "08201020001000", - account: shopWallets[0].address, + wallet: shopWallets[0], }, { - shopId: "F000200", + shopId: "", + name: "Shop2", provideWaitTime: 0, providePercent: 6, - phone: "08201020001001", - account: shopWallets[1].address, + wallet: shopWallets[1], }, { - shopId: "F000300", + shopId: "", + name: "Shop3", provideWaitTime: 0, providePercent: 7, - phone: "08201020001002", - account: shopWallets[2].address, + wallet: shopWallets[2], }, { - shopId: "F000400", + shopId: "", + name: "Shop4", provideWaitTime: 0, providePercent: 8, - phone: "08201020001003", - account: shopWallets[3].address, + wallet: shopWallets[3], }, { - shopId: "F000500", + shopId: "", + name: "Shop5", provideWaitTime: 0, providePercent: 9, - phone: "08201020001004", - account: shopWallets[4].address, + wallet: shopWallets[4], }, { - shopId: "F000600", + shopId: "", + name: "Shop6", provideWaitTime: 0, providePercent: 10, - phone: "08201020001005", - account: shopWallets[5].address, + wallet: shopWallets[5], }, ]; + before("Set Shop ID", async () => { + for (const elem of shopData) { + elem.shopId = ContractUtils.getShopId(elem.name, elem.wallet.address); + } + }); + before("Deploy", async () => { await deployAllContract(); }); @@ -1232,11 +1248,17 @@ describe("Test for Ledger", () => { for (const elem of shopData) { await expect( shopCollection - .connect(validator1) - .add(elem.shopId, elem.provideWaitTime, elem.providePercent, elem.account) + .connect(elem.wallet) + .add(elem.shopId, elem.name, elem.provideWaitTime, elem.providePercent) ) .to.emit(shopCollection, "AddedShop") - .withArgs(elem.shopId, elem.provideWaitTime, elem.providePercent, elem.account); + .withNamedArgs({ + shopId: elem.shopId, + name: elem.name, + provideWaitTime: elem.provideWaitTime, + providePercent: elem.providePercent, + account: elem.wallet.address, + }); } expect(await shopCollection.shopsLength()).to.equal(shopData.length); }); @@ -1386,48 +1408,54 @@ describe("Test for Ledger", () => { const shopData: IShopData[] = [ { shopId: "F000100", + name: "Shop1", provideWaitTime: 0, providePercent: 1, - phone: "08201020001000", - account: shopWallets[0].address, + wallet: shopWallets[0], }, { shopId: "F000200", + name: "Shop2", provideWaitTime: 0, providePercent: 1, - phone: "08201020001001", - account: shopWallets[1].address, + wallet: shopWallets[1], }, { shopId: "F000300", + name: "Shop3", provideWaitTime: 0, providePercent: 1, - phone: "08201020001002", - account: shopWallets[2].address, + wallet: shopWallets[2], }, { shopId: "F000400", + name: "Shop4", provideWaitTime: 0, providePercent: 1, - phone: "08201020001003", - account: shopWallets[3].address, + wallet: shopWallets[3], }, { shopId: "F000500", + name: "Shop5", provideWaitTime: 0, providePercent: 1, - phone: "08201020001004", - account: shopWallets[4].address, + wallet: shopWallets[4], }, { shopId: "F000600", + name: "Shop6", provideWaitTime: 0, providePercent: 1, - phone: "08201020001005", - account: shopWallets[5].address, + wallet: shopWallets[5], }, ]; + before("Set Shop ID", async () => { + for (const elem of shopData) { + elem.shopId = ContractUtils.getShopId(elem.name, elem.wallet.address); + } + }); + before("Deploy", async () => { await deployAllContract(); }); @@ -1443,11 +1471,17 @@ describe("Test for Ledger", () => { for (const elem of shopData) { await expect( shopCollection - .connect(validator1) - .add(elem.shopId, elem.provideWaitTime, elem.providePercent, elem.account) + .connect(elem.wallet) + .add(elem.shopId, elem.name, elem.provideWaitTime, elem.providePercent) ) .to.emit(shopCollection, "AddedShop") - .withArgs(elem.shopId, elem.provideWaitTime, elem.providePercent, elem.account); + .withNamedArgs({ + shopId: elem.shopId, + name: elem.name, + provideWaitTime: elem.provideWaitTime, + providePercent: elem.providePercent, + account: elem.wallet.address, + }); } expect(await shopCollection.shopsLength()).to.equal(shopData.length); }); @@ -1705,26 +1739,10 @@ describe("Test for Ledger", () => { expect(withdrawalAmount).to.equal(amount2); }); - it("Link phone-wallet of the shop", async () => { - const nonce = await linkCollectionContract.nonceOf(shopWallets[shopIndex].address); - const phoneHash = ContractUtils.getPhoneHash(shop.phone); - const signature = await ContractUtils.signRequestHash(shopWallets[shopIndex], phoneHash, nonce); - requestId = ContractUtils.getRequestId(phoneHash, shopWallets[shopIndex].address, nonce); - await expect( - linkCollectionContract - .connect(relay) - .addRequest(requestId, phoneHash, shopWallets[shopIndex].address, signature) - ) - .to.emit(linkCollectionContract, "AddedRequestItem") - .withArgs(requestId, phoneHash, shopWallets[shopIndex].address); - await linkCollectionContract.connect(validator1).voteRequest(requestId); - await linkCollectionContract.connect(validator1).countVote(requestId); - }); - it("Open Withdrawal", async () => { await expect( shopCollection - .connect(shopWallets[shopIndex].connect(hre.waffle.provider)) + .connect(shopData[shopIndex].wallet.connect(hre.waffle.provider)) .openWithdrawal(shop.shopId, amount2) ) .to.emit(shopCollection, "OpenedWithdrawal") @@ -1740,7 +1758,7 @@ describe("Test for Ledger", () => { it("Close Withdrawal", async () => { await expect( shopCollection - .connect(shopWallets[shopIndex].connect(hre.waffle.provider)) + .connect(shopData[shopIndex].wallet.connect(hre.waffle.provider)) .closeWithdrawal(shop.shopId) ) .to.emit(shopCollection, "ClosedWithdrawal") @@ -1754,7 +1772,7 @@ describe("Test for Ledger", () => { }); }); }); -*/ + context("Multi Currency", () => { const userData: IUserData[] = [ { @@ -1844,48 +1862,54 @@ describe("Test for Ledger", () => { const shopData: IShopData[] = [ { shopId: "F000100", + name: "Shop1", provideWaitTime: 0, providePercent: 1, - phone: "08201020001000", - account: shopWallets[0].address, + wallet: shopWallets[0], }, { shopId: "F000200", + name: "Shop2", provideWaitTime: 0, providePercent: 1, - phone: "08201020001001", - account: shopWallets[1].address, + wallet: shopWallets[1], }, { shopId: "F000300", + name: "Shop3", provideWaitTime: 0, providePercent: 1, - phone: "08201020001002", - account: shopWallets[2].address, + wallet: shopWallets[2], }, { shopId: "F000400", + name: "Shop4", provideWaitTime: 0, providePercent: 1, - phone: "08201020001003", - account: shopWallets[3].address, + wallet: shopWallets[3], }, { shopId: "F000500", + name: "Shop5", provideWaitTime: 0, providePercent: 1, - phone: "08201020001004", - account: shopWallets[4].address, + wallet: shopWallets[4], }, { shopId: "F000600", + name: "Shop6", provideWaitTime: 0, providePercent: 1, - phone: "08201020001005", - account: shopWallets[5].address, + wallet: shopWallets[5], }, ]; + before("Set Shop ID", async () => { + for (const elem of shopData) { + elem.shopId = ContractUtils.getShopId(elem.name, elem.wallet.address); + } + }); + before("Deploy", async () => { await deployAllContract(); }); @@ -1908,34 +1932,20 @@ describe("Test for Ledger", () => { for (const elem of shopData) { await expect( shopCollection - .connect(validator1) - .add(elem.shopId, elem.provideWaitTime, elem.providePercent, elem.account) + .connect(elem.wallet) + .add(elem.shopId, elem.name, elem.provideWaitTime, elem.providePercent) ) .to.emit(shopCollection, "AddedShop") - .withArgs(elem.shopId, elem.provideWaitTime, elem.providePercent, elem.account); + .withNamedArgs({ + shopId: elem.shopId, + name: elem.name, + provideWaitTime: elem.provideWaitTime, + providePercent: elem.providePercent, + account: elem.wallet.address, + }); } expect(await shopCollection.shopsLength()).to.equal(shopData.length); }); - - it("Link phone-wallet of shops", async () => { - for (let idx = 0; idx < shopData.length; idx++) { - const shop = shopData[idx]; - const wallet = shopWallets[idx]; - const nonce = await linkCollectionContract.nonceOf(wallet.address); - const phoneHash = ContractUtils.getPhoneHash(shop.phone); - const signature = await ContractUtils.signRequestHash(wallet, phoneHash, nonce); - requestId = ContractUtils.getRequestId(phoneHash, wallet.address, nonce); - await expect( - linkCollectionContract - .connect(relay) - .addRequest(requestId, phoneHash, wallet.address, signature) - ) - .to.emit(linkCollectionContract, "AddedRequestItem") - .withArgs(requestId, phoneHash, wallet.address); - await linkCollectionContract.connect(validator1).voteRequest(requestId); - await linkCollectionContract.connect(validator1).countVote(requestId); - } - }); }); context("Prepare foundation's asset", () => { diff --git a/packages/faker/scripts/createShopId.ts b/packages/faker/scripts/createShopId.ts new file mode 100644 index 00000000..10675167 --- /dev/null +++ b/packages/faker/scripts/createShopId.ts @@ -0,0 +1,18 @@ +import { ContractUtils } from "../src/utils/ContractUtils"; +import fs from "fs"; +import { IShopData } from "../src/types"; + +async function main() { + const shops = JSON.parse(fs.readFileSync("./src/data/shops.json", "utf8")) as IShopData[]; + for (const shop of shops) { + shop.shopId = ContractUtils.getShopId(shop.name, shop.address); + } + console.log(JSON.stringify(shops)); +} + +// We recommend this pattern to be able to use async/await everywhere +// and properly handle errors. +main().catch((error) => { + console.error(error); + process.exitCode = 1; +}); diff --git a/packages/faker/src/data/shops.json b/packages/faker/src/data/shops.json index f28265d3..f89852af 100644 --- a/packages/faker/src/data/shops.json +++ b/packages/faker/src/data/shops.json @@ -1,52 +1,82 @@ [ { - "shopId": "F000100", + "shopId": "0xbe96d74202df38fd21462ffcef10dfe0fcbd7caa3947689a3903e8b6b8749fda", + "name": "Shop-0001", "provideWaitTime": 0, - "providePercent": "5" + "providePercent": "5", + "address": "0xafFe745418Ad24c272175e5B58610A8a35e2EcDa", + "privateKey": "0xa237d68cbb66fd5f76e7b321156c46882546ad87d662dec8b82703ac31efbf0a" }, { - "shopId": "F000200", + "shopId": "0x5f59d6b480ff5a30044dcd7fe3b28c69b6d0d725ca469d1b685b57dfc1055d7f", + "name": "Shop-0002", "provideWaitTime": 0, - "providePercent": "5" + "providePercent": "5", + "address": "0xD10ADf251463A260242c216c8c7D3e736eBdB398", + "privateKey": "0x05152ad8d5b14d3f65539e0e42131bc72cbdd16c486cb215d60b7dc113ca1ebd" }, { - "shopId": "F000300", + "shopId": "0x08f12f827f0521be34e7563948dc778cb80f7498cebb57cb1a62840d96eb143c", + "name": "Shop-0003", "provideWaitTime": 0, - "providePercent": "5" + "providePercent": "5", + "address": "0xD12e250C8F5C3720297CeBF5A50655A8e2348847", + "privateKey": "0xf4b8aa615834c57d1e4836c683c8d3460f8ff232667dc317f82844e674ee4f26" }, { - "shopId": "F000400", + "shopId": "0xbefa86be32da60a87a843bf3e63e77092040ee044f854e8d318d1eb18d208f4d", + "name": "Shop-0004", "provideWaitTime": 0, - "providePercent": "5" + "providePercent": "5", + "address": "0x57D5E271FF8A4d49AE793B8b6Cf005E33FA4FA48", + "privateKey": "0xe58b3ae0e68a04996d6c13c9f9cb65b2d88ada662f28edd67db8c8e1ef45eed4" }, { - "shopId": "F000500", + "shopId": "0x3ecc54754b835d04ee5b4df7d0d0eb4e0eafc33ac8de4d282d641f7f054d1c27", + "name": "Shop-0005", "provideWaitTime": 0, - "providePercent": "5" + "providePercent": "5", + "address": "0x14De3f38D8deB7fFc5c15859bA05e4B088F8F631", + "privateKey": "0x1f2246394971c643d371a2b2ab9176d34b98c0a84a6aa5e4e53f73ab6119dcc1" }, { - "shopId": "F000600", + "shopId": "0x548b7faa282b8721218962e3c1ae43608009534663de91a1548e37cc1c6980a5", + "name": "Shop-000600", "provideWaitTime": 0, - "providePercent": "5" + "providePercent": "5", + "address": "0xA9c5559da87A7511D28e87C751dAfE65374Ce59f", + "privateKey": "0x49d28e02787ca6f2827065c83c9c4de2369b4d18d132505d3c01ba35a4558214" }, { - "shopId": "F000700", + "shopId": "0x08bde9ef98803841f22e8bc577a69fc47913914a8f5fa60e016aaa74bc86dd47", + "name": "Shop-0007", "provideWaitTime": 0, - "providePercent": "5" + "providePercent": "5", + "address": "0xAAa610aE6711B810921ca06629c42a3E127851cd", + "privateKey": "0xd72fb7fe49fd18f92481cbee186050816631391b4a25d579b7cff7efdf7099d3" }, { - "shopId": "F000800", + "shopId": "0x04ef11be936f49f6388dd20d062e43170fd7ce9e968e51426317e284b9309361", + "name": "Shop-0008", "provideWaitTime": 0, - "providePercent": "5" + "providePercent": "5", + "address": "0x4BbfEd63b19954A357C1Dfc3Ba8820d2eE31Bbcf", + "privateKey": "0x90ee852d612e080fb99914d40e0cd75edf928ca895bdda8b91be4b464c55edfc" }, { - "shopId": "F000900", + "shopId": "0x6bad0e0f6ad0fdd7660393b45f452a0eca3f6f1f0eeb25c5902e46a1ffeeef3f", + "name": "Shop-0009", "provideWaitTime": 0, - "providePercent": "5" + "providePercent": "5", + "address": "0xe3812c628b1E0245Eed4A548914e32C9eeFda019", + "privateKey": "0x8bfcb398c9cb1c7c11790a2293f6d4d8c0adc5f2bd3620561dd81e2db2e9a83e" }, { - "shopId": "F001000", + "shopId": "0x2a23595cf31762a61502546e8b9f947baf3bd55040d9bd535f8afdbff409fa60", + "name": "Shop-0010", "provideWaitTime": 0, - "providePercent": "5" + "providePercent": "5", + "address": "0xfD8072e4809BFADd90ad6D60aF31C8dCd7a46990", + "privateKey": "0x77962b6be5cd2ab0c692fe500f50965b5051822d91fece18dcd256dc79182305" } ] diff --git a/packages/faker/src/data/users.json b/packages/faker/src/data/users.json index 20e5c0e8..d0289d88 100644 --- a/packages/faker/src/data/users.json +++ b/packages/faker/src/data/users.json @@ -1,700 +1,700 @@ [ { "idx": 0, - "phone":"08201010002000", + "phone": "08201010002000", "address": "0x64D111eA9763c93a003cef491941A011B8df5a49", "privateKey": "0x70438bc3ed02b5e4b76d496625cb7c06d6b7bf4362295b16fdfe91a046d4586c", "pointType": 0 }, { "idx": 1, - "phone":"08201010002001", + "phone": "08201010002001", "address": "0x3FE8D00143bd0eAd2397D48ba0E31E5E1268dBfb", "privateKey": "0x44868157d6d3524beb64c6ae41ee6c879d03c19a357dadb038fefea30e23cbab", "pointType": 0 }, { "idx": 2, - "phone":"08201010002002", + "phone": "08201010002002", "address": "0xCf44157e9df307c90FC7762933Ac1e2921e8b39E", "privateKey": "0x11855bdc610b27e6b98de50715c947dc7acd95166d70d66b773f06b328ee8b5c", "pointType": 0 }, { "idx": 3, - "phone":"08201010002003", + "phone": "08201010002003", "address": "0xf26f7844f5B4770c47f34ea35a03B2b3534d08FE", "privateKey": "0x2e981a3691ff15706d808b457699ddd46fb9ebf8d824295fb585e71e1db3c4c1", "pointType": 0 }, { "idx": 4, - "phone":"08201010002004", + "phone": "08201010002004", "address": "0x7Bac9e662E2C1Cf9f6f97F8CaF9c7aDE8F146bd1", "privateKey": "0xb93f43bdafc9efee5b223735a0dd4efef9522f2db5b9f70889d6fa6fcead50c4", "pointType": 0 }, { "idx": 5, - "phone":"08201010002005", + "phone": "08201010002005", "address": "0x852DB1c83e17BE9fba782c97436F47cE4ad2Af83", "privateKey": "0xcd0050e45b8ed7cf14055a640a129c81c805128a3711dbe5af1c5b434ba2d4cc", "pointType": 0 }, { "idx": 6, - "phone":"08201010002006", + "phone": "08201010002006", "address": "0x5857f28FDFE295bde60967c749199cAfB89C720F", "privateKey": "0x1df07300f5c65983b16d0b28e4fce3def7141cb573df00d077c8a8b12de47be0", "pointType": 0 }, { "idx": 7, - "phone":"08201010002007", + "phone": "08201010002007", "address": "0x98b0fdb6C23C7C80B4728579e76F4aD95fe7014A", "privateKey": "0xd96b986c2d61fa843f856ad621d4343705b296d88e3c96a17c726d130e95118e", "pointType": 0 }, { "idx": 8, - "phone":"08201010002008", + "phone": "08201010002008", "address": "0xF51A41cD49ff9B280Acea3768f8624003C69F3ea", "privateKey": "0x115094e272f33caa245e5458eb0debd7864eb5f71980d508a27612845540ad99", "pointType": 0 }, { "idx": 9, - "phone":"08201010002009", + "phone": "08201010002009", "address": "0x8340Bb9Cd5C3827c213beB23b05E1815c4bE9AFA", "privateKey": "0x5c7744beb5c2a2369f22879eeab289ae6fd2d46c2ff348fcdd5d3c70d846a1a1", "pointType": 0 }, { "idx": 10, - "phone":"08201010002010", + "phone": "08201010002010", "address": "0xf3802b4c177aE5ca5ED022Ced2643dAE79E3b824", "privateKey": "0x46ba360778a00c5bf9322a702bbbd38c7a56f20f9360a14686f5b71834922569", "pointType": 0 }, { "idx": 11, - "phone":"08201010002011", + "phone": "08201010002011", "address": "0x35004290E2890782DE456A8C0787f0747E93089B", "privateKey": "0x6111ebbc274bd07fb2fd53d66652766686e85f21cfdf615f3236e687c7aabfa2", "pointType": 0 }, { "idx": 12, - "phone":"08201010002012", + "phone": "08201010002012", "address": "0xB0ddD72EEB6b692505b99C912c30a5509f4D9062", "privateKey": "0x1642cadf4dc8fc81dfe0c148227836a1c22230846701de1f12db59f031b8067c", "pointType": 0 }, { "idx": 13, - "phone":"08201010002013", + "phone": "08201010002013", "address": "0xAc09cdb210e7F5528e3b045F6726A145d08E25be", "privateKey": "0x86e806c4d2e1224ed91c78af00c3ef328d023db20027d892b05d551bff8ad910", "pointType": 0 }, { "idx": 14, - "phone":"08201010002014", + "phone": "08201010002014", "address": "0xdD30Ef7eefC7ec283d9B573D86e11a77E9b3F722", "privateKey": "0xe7b52d74383c5e1a576b84eb96384627dbb50469fbb91bfa227ddfe250e20a0e", "pointType": 0 }, { "idx": 15, - "phone":"08201010002015", + "phone": "08201010002015", "address": "0xA579D3De3fb6613017A03C5C66d4f1Cf3d37b427", "privateKey": "0xba5ee30d9313800952d3d3f6d367039c22bb09f94ec57e4bccc506f0da1fa552", "pointType": 0 }, { "idx": 16, - "phone":"08201010002016", + "phone": "08201010002016", "address": "0x49760921d14C3343f04Bf46371aD782C1478F5BC", "privateKey": "0xbbadbc87a1dc7cd6f71fbc374bc5ec77b3680dbb3f59074c7c3682fec24c322f", "pointType": 0 }, { "idx": 17, - "phone":"08201010002017", + "phone": "08201010002017", "address": "0x7B7B7Fb2613Dd7286DcAe541bF2391c9754eA3cd", "privateKey": "0xfefd0cb39ecbaebb7b4c19a7288458809a906aed6f001202a3e2cb01a6d4ec23", "pointType": 0 }, { "idx": 18, - "phone":"08201010002018", + "phone": "08201010002018", "address": "0xB4008dDce19b0061317726c5fC3413d8C8C828Eb", "privateKey": "0xc5cfabd6975b0f83bb367df4679da25450be793839d0bbefdc4989f3e2376eec", "pointType": 0 }, { "idx": 19, - "phone":"08201010002019", + "phone": "08201010002019", "address": "0xd1D879664617032Da2Da21CF3DA9e58a487673A9", "privateKey": "0x3d53fea04641879be6a3a8a8d61d4d441eb401d7b3fe352eff9f7ac8ba1a4ec9", "pointType": 0 }, { "idx": 20, - "phone":"08201010002020", + "phone": "08201010002020", "address": "0x71770F1Ed060051ebb6f3f2350418ea339268505", "privateKey": "0x3dc149190a33487e968beaaa4f0cab869e02534b8d9d4c999d306c49ad4696e8", "pointType": 0 }, { "idx": 21, - "phone":"08201010002021", + "phone": "08201010002021", "address": "0x903063cE4dBF5C61bB2f4d697C082Ac3F26c9e03", "privateKey": "0x95c6a667040a653ccd200885b6e67670cc115c29b13b1c2022993d13635a0b31", "pointType": 0 }, { "idx": 22, - "phone":"08201010002022", + "phone": "08201010002022", "address": "0x74B936f54fDbDa9324a871226835944D6468CdBb", "privateKey": "0xae5817e4a2ea1371cfd4d35ec5ba155585d3cebe18e6197bc4e030bc0e3dd9f8", "pointType": 0 }, { "idx": 23, - "phone":"08201010002023", + "phone": "08201010002023", "address": "0xA6543b00acde8F61475B089474EDdE92223103A5", "privateKey": "0x32990d3f18c3625901d5254f517daa5ef1c43383027a3b98902f5ebf9cb5a692", "pointType": 0 }, { "idx": 24, - "phone":"08201010002024", + "phone": "08201010002024", "address": "0xa8201943223834BaB8e4C877971568e8daf4963F", "privateKey": "0x6b4d24d4809dad462f6ca8ff1fb71b64091d0ff11c3ebc548c6cddd01dfc8c0f", "pointType": 0 }, { "idx": 25, - "phone":"08201010002025", + "phone": "08201010002025", "address": "0xBE43a4598aB331D60054726037F942a432E2b0FA", "privateKey": "0x98b748b35f47c3498271e1b5f8da35b40670214a775ca0f07b27780ab8135ab1", "pointType": 0 }, { "idx": 26, - "phone":"08201010002026", + "phone": "08201010002026", "address": "0x096710E3B5ccAb0a35501226f7D00B57b41901F3", "privateKey": "0x9cfb97b7abe04557a83cf19611b5ec6e674ca3fe5dffe37ed047a0fe9892fb9c", "pointType": 0 }, { "idx": 27, - "phone":"08201010002027", + "phone": "08201010002027", "address": "0x06796CE510010e90F519e9cBE28E5075c7e80Ba8", "privateKey": "0x3085e5b217e027e094822aa171445f971fbd5aec14b1ae1cdc8ac759af24472d", "pointType": 0 }, { "idx": 28, - "phone":"08201010002028", + "phone": "08201010002028", "address": "0x4aCB655Ec9cb9b7bA53059D2754Da628F97E5520", "privateKey": "0x63015d622dac9ea25bca0749eca67698d78ee22c29bd4536e000d65325600cec", "pointType": 0 }, { "idx": 29, - "phone":"08201010002029", + "phone": "08201010002029", "address": "0x58cd45F5461DFa1c03e44459f700Aa530488Fe7f", "privateKey": "0xe9edb4354287e55d123672088c9c6b55ead2859b3b577d02f6fd33c7a99e3164", "pointType": 0 }, { "idx": 30, - "phone":"08201010002030", + "phone": "08201010002030", "address": "0xcD2803008856100264F17140d4d977768C36B546", "privateKey": "0x678daaa72339201608534313be62c7d3835c7baa1dc588ebcb1eb865385ca54e", "pointType": 0 }, { "idx": 31, - "phone":"08201010002031", + "phone": "08201010002031", "address": "0x8f05bddf379d89c827bAEFE43a5eca3aBE2CAf49", "privateKey": "0xf02e9bf477c21e05b60de4e8a65824d9aae194eccd193245a6296c13dc675227", "pointType": 0 }, { "idx": 32, - "phone":"08201010002032", + "phone": "08201010002032", "address": "0x7c86E333501Ac8BfA7b5a4A9a166922d1872FeBa", "privateKey": "0xb30667148df49d3ffe8e62e72df69358e286f4db5f487c5699dd3ca545a495cf", "pointType": 0 }, { "idx": 33, - "phone":"08201010002033", + "phone": "08201010002033", "address": "0x809d7F5B2AC27Fc3aBc8441EC31386a80EdA1592", "privateKey": "0x9f09e74e517af6f604b4cf5d7061fe2736638b7b81809e06fb1cb1e10b23a58b", "pointType": 0 }, { "idx": 34, - "phone":"08201010002034", + "phone": "08201010002034", "address": "0x7642b1EC5175CC389a62632E0AF253Cf78bb07b9", "privateKey": "0x843bc9928bc75cbd1296264813b5e125f32497eae208a2c1d4ea6532a9e52490", "pointType": 0 }, { "idx": 35, - "phone":"08201010002035", + "phone": "08201010002035", "address": "0x2Fe00A97b2e578bF7381CFA0379d3756372fF644", "privateKey": "0x756d1ba4c61888a602cbfb75ee54ebeb9af22d75834522779bc24c0661242185", "pointType": 0 }, { "idx": 36, - "phone":"08201010002036", + "phone": "08201010002036", "address": "0x265A22e880fD793e277625ea8e4f7D58D40C419F", "privateKey": "0xee5731e8b4ce2464e41990b6a4ce826cc61a9813d0ce4d7e1ec553f4961502e1", "pointType": 0 }, { "idx": 37, - "phone":"08201010002037", + "phone": "08201010002037", "address": "0x89e3b2D91ecaf08016eEDb966c1fecA1e326714e", "privateKey": "0x329357385b1a8ee0425ec907e52916a384cb991d76d1e595a619c9b6957d080c", "pointType": 0 }, { "idx": 38, - "phone":"08201010002038", + "phone": "08201010002038", "address": "0x2c620BdACb2ef5f7AE80Ca323f81158845A1605e", "privateKey": "0x3432e4b1caec0d0733307e427e10b2732b1c1a70af331a3c08ae47a47312d6be", "pointType": 0 }, { "idx": 39, - "phone":"08201010002039", + "phone": "08201010002039", "address": "0x7CDaDf72FDbE02641027ACD0Aa517D3cA76996eF", "privateKey": "0x91388010aa90bf0200a6e39dee390fd5a2f5db12a50571c83a0ef16f91a40b7e", "pointType": 0 }, { "idx": 40, - "phone":"08201010002040", + "phone": "08201010002040", "address": "0xb92E3679F3DA94003063FCf72E525bC7Df99bA3C", "privateKey": "0xb55231ba7970293f5a8ee4452ebf937d1f3d5f64885bd713f228786f87708de3", "pointType": 0 }, { "idx": 41, - "phone":"08201010002041", + "phone": "08201010002041", "address": "0x8cD7f4FD8ADd776B28D6A6A61625a89b1738c8d1", "privateKey": "0xb25642f78c06f5b6cb145f00724e8ee7ee4f6f7a36d801b2605ce73ca88833e0", "pointType": 0 }, { "idx": 42, - "phone":"08201010002042", + "phone": "08201010002042", "address": "0xdCdb0368728F93c3a7aAef38980B5f0933cCcF31", "privateKey": "0x4f8835465e067ecb63035db49651ec195708761ff751815dbed1c232fb4235d4", "pointType": 0 }, { "idx": 43, - "phone":"08201010002043", + "phone": "08201010002043", "address": "0x58F2660975Ac5a747e2D3944AA4649EE460fB26D", "privateKey": "0x8ecdc67a86bfb5be8e2fdd789977df32b0a8c70eefa7406a9701141232533f66", "pointType": 0 }, { "idx": 44, - "phone":"08201010002044", + "phone": "08201010002044", "address": "0xA432821b87110a36f4163E1c5f66185efCB69117", "privateKey": "0xe82958390a9e9706370f550cbda28f6a273faf835be363ec45ab99ed68039797", "pointType": 0 }, { "idx": 45, - "phone":"08201010002045", + "phone": "08201010002045", "address": "0x2122bf35f2D64E64483A4289cD0Bcd613b1bcAFa", "privateKey": "0x5757a560ba6caabe98b77c04b77ad61eae34776b9613f698d15edef1e30ce95c", "pointType": 0 }, { "idx": 46, - "phone":"08201010002046", + "phone": "08201010002046", "address": "0xD303166E007f601cfAB726C8d078BE75e7fE809a", "privateKey": "0xbb97770147c281103a36b1ce9720307e98ed74dd69eb7a87eceb25df9b1f42ea", "pointType": 0 }, { "idx": 47, - "phone":"08201010002047", + "phone": "08201010002047", "address": "0x94c0Cd28e2988f58388E709eB2010c721e5c32E2", "privateKey": "0x1b8eb15d5010a6673963207683fba7d5875a8aeb9d8c265351bb3934ca99bfcb", "pointType": 0 }, { "idx": 48, - "phone":"08201010002048", + "phone": "08201010002048", "address": "0xDF32A6dD8993528135C2e13B18dDAD3f78c581cF", "privateKey": "0xeb50af73ef5b4cf3fc30dbd2334bd10ca285e266eb160990a21811087b144c4a", "pointType": 0 }, { "idx": 49, - "phone":"08201010002049", + "phone": "08201010002049", "address": "0xFF94F0D95F4130A7212C5D91850373D5Fe9eeAF7", "privateKey": "0xa158fa18c8109cc560fa76d8fbc29017a312924de0eea58db085e5f241afce5a", "pointType": 0 }, { "idx": 50, - "phone":"08201010002050", + "phone": "08201010002050", "address": "0x90Ab97F65F1A5d02320e887fd07066c3e78c5846", "privateKey": "0x833bfa4afbb90959863ab74a856a0714bf1c8a0fccb7a1c3fe919a1aca2938d2", "pointType": 1 }, { "idx": 51, - "phone":"08201010002051", + "phone": "08201010002051", "address": "0x14C17C2286324Db12A47bab0477D100dabB92b82", "privateKey": "0x913d15c13b4719152f419249d629172c84c48b4129d65a8dbd81c96d65ab9877", "pointType": 1 }, { "idx": 52, - "phone":"08201010002052", + "phone": "08201010002052", "address": "0xB2E1578C22c1d918706EC6314a15678ccD9D918C", "privateKey": "0xd62d89ded73ef4fa38a339608f196019cdcd60e5f19e9adea5456685b691b6c9", "pointType": 1 }, { "idx": 53, - "phone":"08201010002053", + "phone": "08201010002053", "address": "0xc3b44fA9c5eF71c8e4D2C7d71E46aa5306a24f18", "privateKey": "0xad02f8ffb2bcb3c6d2c1bbc67e90e24697c12bdb57416e91386f2b40582c0d6a", "pointType": 1 }, { "idx": 54, - "phone":"08201010002054", + "phone": "08201010002054", "address": "0xBADDa09A6543EF1c9dAcaF1B9f556683aA07Df17", "privateKey": "0x3a9e72cfca22ca74267d2b8b8373535bba25af595b94244c04d83ba0a5192c70", "pointType": 1 }, { "idx": 55, - "phone":"08201010002055", + "phone": "08201010002055", "address": "0xbAC552C9638a004642C539af7c730DF3cA78835d", "privateKey": "0x77768416b1d1b6f1d27c74e9f0579f114b4e7cecfd9633dc6ecf635b75df4e4f", "pointType": 1 }, { "idx": 56, - "phone":"08201010002056", + "phone": "08201010002056", "address": "0x821438f750867b0c4cB0F4C96f95c21b263238DE", "privateKey": "0x2603bcac3316baa54a4c522381c133a5561ddd75a093a400250b71a3e17c4036", "pointType": 1 }, { "idx": 57, - "phone":"08201010002057", + "phone": "08201010002057", "address": "0x3fD2AF3AC475B764F2d94F52fA48135b2E71E3b6", "privateKey": "0xc5a59d32c076b0982199736fd31f36fbc9ddb2aae94c4434415e7ea470065b32", "pointType": 1 }, { "idx": 58, - "phone":"08201010002058", + "phone": "08201010002058", "address": "0x65738d6AfD0eac08B0375A628bFc96BF4e6F5E4B", "privateKey": "0x95aec98dc6e55b8d96bb1c6359851efb64bc1ba2ec52575898e57d296beceb2d", "pointType": 1 }, { "idx": 59, - "phone":"08201010002059", + "phone": "08201010002059", "address": "0x366Ec0bA6e9A28ef6CBE4Ddb900028336F67b32f", "privateKey": "0xf904d7431d9752b14f632c5a75fabfa555202a651394a441b3a832c17749c4f6", "pointType": 1 }, { "idx": 60, - "phone":"08201010002060", + "phone": "08201010002060", "address": "0x967614054b6906B39d449f53C0d8A7A3F4e50584", "privateKey": "0x901216b17bfa65f762889ed7d074139543c3930205af32ff1820c18d42d2699b", "pointType": 1 }, { "idx": 61, - "phone":"08201010002061", + "phone": "08201010002061", "address": "0xB09353ABE11E1F5e6Bff8cD7743322d30D9dE44E", "privateKey": "0xa284e364aa4210727f365bdb79388d6ba52c90881152791dfe81ae4db52be843", "pointType": 1 }, { "idx": 62, - "phone":"08201010002062", + "phone": "08201010002062", "address": "0x19594858cE5cC77bF1ff71B61214D41e0d5a1aE8", "privateKey": "0x91cbdcc1cc6e0e0c6114de4b7e3cff89b48386e00993609f370adee3039d6678", "pointType": 1 }, { "idx": 63, - "phone":"08201010002063", + "phone": "08201010002063", "address": "0xfaBC045A3d34A070dc0a4e34d916CBf1Febed8e5", "privateKey": "0xd3ab09578476303325cd01befe8c2345dcb72f2ef11b025fedf754adb8bd7acf", "pointType": 1 }, { "idx": 64, - "phone":"08201010002064", + "phone": "08201010002064", "address": "0x7De5c9cE240bdeb4B35E742BEec3f81b9657c724", "privateKey": "0xfdb7e230a1c2e179281316c3c9bd26deba5cc49a470f2e81628e484bb1e9b135", "pointType": 1 }, { "idx": 65, - "phone":"08201010002065", + "phone": "08201010002065", "address": "0xAfCA35269d937662Bf2b27a2299aeEB0FB42Ea17", "privateKey": "0xdf2448abc706f7f1fbfd677e94560b31133b151bc56b3845a114d7dc6c67a25f", "pointType": 1 }, { "idx": 66, - "phone":"08201010002066", + "phone": "08201010002066", "address": "0x35aCaF5bD718349620545ec339B168B23d1A3dcd", "privateKey": "0xa2d27c16136206ad1363f00c247a5594410caf7be25056ed1ef3f83f5d15e615", "pointType": 1 }, { "idx": 67, - "phone":"08201010002067", + "phone": "08201010002067", "address": "0x4324Fb178B841a436c18F3191BFa75026d4112B2", "privateKey": "0x923774230aa5b69c24a9a2631c1f6c3a701a840d0834e607950207df7753ed6e", "pointType": 1 }, { "idx": 68, - "phone":"08201010002068", + "phone": "08201010002068", "address": "0xC9c29fD8fF7204965bdE443cd4ca4c35B451B19e", "privateKey": "0xb74eb215de25217bdc80472039609bab275890d7e1b2a491fae1b479f523c26e", "pointType": 1 }, { "idx": 69, - "phone":"08201010002069", + "phone": "08201010002069", "address": "0x42c7E54a2CB757F121180Be68bc1b5fd9Db1c8f5", "privateKey": "0x305d6202a3edbb6c6bed32bb2544f593cf30df96ba3e5e6aa38a26c53031e043", "pointType": 1 }, { "idx": 70, - "phone":"08201010002070", + "phone": "08201010002070", "address": "0xAC7Fe12CeDA522Bf1cb0D3A30272C3A3E7FE177f", "privateKey": "0x71b20d76ed966d6a7860de9ec2f99b24d1f1f4365449c0af831b8adba609b20c", "pointType": 1 }, { "idx": 71, - "phone":"08201010002071", + "phone": "08201010002071", "address": "0xa1E4b09110181051585B990d7024397FE6370346", "privateKey": "0xaf898e887fd169a7c75b2b0587f7e32a97ce05016da7765d84a9b026197be91c", "pointType": 1 }, { "idx": 72, - "phone":"08201010002072", + "phone": "08201010002072", "address": "0xcB41a82601703A3EDe0fc30d994ad43888F7c511", "privateKey": "0x48d78d317df2e314c16ae80f7ca29b874b12e0610e5c1d7fa772040ebd4485d9", "pointType": 1 }, { "idx": 73, - "phone":"08201010002073", + "phone": "08201010002073", "address": "0x8e88b88C3BbA79E9E5897bC8D6d8bEf1CAc64f56", "privateKey": "0x01a265e82414c165bd555fd0e45ac14448ea622948c9f9015daedd1faa3987b5", "pointType": 1 }, { "idx": 74, - "phone":"08201010002074", + "phone": "08201010002074", "address": "0x010e3d8c7fec02ce7fA7288D11f1f6C1400FE07A", "privateKey": "0xf2bee079f06cb18fe95abece2f219f692d96d34239e7816d735b96085447f704", "pointType": 1 }, { "idx": 75, - "phone":"08201010002075", + "phone": "08201010002075", "address": "0xb2b5868f995F88293011D10e87ae0e9E979b1F16", "privateKey": "0x0e35e09cc63f3da830011d68835231eb57e80c0780dd0aa4ca9caa4d40b7d560", "pointType": 1 }, { "idx": 76, - "phone":"08201010002076", + "phone": "08201010002076", "address": "0xD391edCddbc48410cC66D022932FDd517f38172B", "privateKey": "0xd0477924d13dae8529ee89c0e85f49da8e373f0caf8d2de4f2af92f3227476e3", "pointType": 1 }, { "idx": 77, - "phone":"08201010002077", + "phone": "08201010002077", "address": "0x6a03061a10C3E39B59082c01d06ca48fc5257B36", "privateKey": "0x8eed3c9bff85c168d1f533dbff2f41bd016900dc0ba40880b3d868021740bce9", "pointType": 1 }, { "idx": 78, - "phone":"08201010002078", + "phone": "08201010002078", "address": "0xEe27eEb9D8b7De85CCF13C953a94f59bd9bbaA92", "privateKey": "0xd9b2e116241042f3032a126eba7f110ad5d91aef895fd531b228960bedf67073", "pointType": 1 }, { "idx": 79, - "phone":"08201010002079", + "phone": "08201010002079", "address": "0xdb757A91b920Cc3AC04F04fc7905F13c4352908d", "privateKey": "0x9b1de659ea30e46aac17f19002c3e22c7f39071cfc63eab6338a3dd4c33f20d9", "pointType": 1 }, { "idx": 80, - "phone":"08201010002080", + "phone": "08201010002080", "address": "0xc41Ae4077732ca2F35745674A8ea60CC3Daca6cB", "privateKey": "0x0f1975d466a30e1d5e765de51b890dd52aa6b96ebcd485b1c4a8ee9326ba7c2b", "pointType": 1 }, { "idx": 81, - "phone":"08201010002081", + "phone": "08201010002081", "address": "0x8d6433eE1105a14cB357739474da40a263bb1b6b", "privateKey": "0x7eadce18a65a9e28644c92b852050e8d758e22fdd93be712893f5fc58d46da9e", "pointType": 1 }, { "idx": 82, - "phone":"08201010002082", + "phone": "08201010002082", "address": "0xf062aa80Dec9c82f7116B1da4438966AC1C746C2", "privateKey": "0xdf0cea945d22364a723dc35bed386a2a86281b9be854feac39e96eebad101453", "pointType": 1 }, { "idx": 83, - "phone":"08201010002083", + "phone": "08201010002083", "address": "0x7fda36C554872bE7Fe2b94F07125496Cb755dA6A", "privateKey": "0x7f64538fb204c0cbb6395a42f23157ef794a49f309c37f721080a5292ed99fab", "pointType": 1 }, { "idx": 84, - "phone":"08201010002084", + "phone": "08201010002084", "address": "0xc47949A63Ed9E163dcBb84443c3FE6702D12a1Ed", "privateKey": "0xcbbafe4ee975942df434fb15b46f313c30f8815477c569cdae4217ddb2a47c1e", "pointType": 1 }, { "idx": 85, - "phone":"08201010002085", + "phone": "08201010002085", "address": "0x3BF101CcA175ebD8a2f475784b59A1f197c4EB87", "privateKey": "0xdb1c949bcd0443ef0e84446bb32b65dca0cd28a07f8a589152623acbeee1be2e", "pointType": 1 }, { "idx": 86, - "phone":"08201010002086", + "phone": "08201010002086", "address": "0x62B811293e809BFc5D1177CCdf0DD8D18C871caA", "privateKey": "0x7b7c89d8a1fc0bd565942c881c153153783d8c8b763816f28ecd4ed1abf57f37", "pointType": 1 }, { "idx": 87, - "phone":"08201010002087", + "phone": "08201010002087", "address": "0x6F7C263aBe2b734ec520166Ecae6C34DD0B7AeEF", "privateKey": "0xa077c86f216fddae34c3d7d954ac03d0945c501e5a8e0018f9f40affd5503b1a", "pointType": 1 }, { "idx": 88, - "phone":"08201010002088", + "phone": "08201010002088", "address": "0x5BD8556a379438B7761dAEe893d33afDA63DdE66", "privateKey": "0x5a90605d881b5535a8bad62f14f50b1a37fea8f20ef85991b0ad783b9cce1a03", "pointType": 1 }, { "idx": 89, - "phone":"08201010002089", + "phone": "08201010002089", "address": "0xeF70Cbb5Bcdb4D8597c1958572875075FaC935aa", "privateKey": "0xdbaea97fa43c58a47b87dd8c6b6f6dabb663dbbadf6f992e765034227c993cb3", "pointType": 1 }, { "idx": 90, - "phone":"08201010002090", + "phone": "08201010002090", "address": "0x3Cc670905d684A19D7318CE02b36183b680aC9Ba", "privateKey": "0xf9e277ac480ac14c04dd1cfd99b340b4c9d485b3116157ef5d2ac8f396c7285d", "pointType": 1 }, { "idx": 91, - "phone":"08201010002091", + "phone": "08201010002091", "address": "0x4f84af3DAe0dff52851Bc51D05579Ce31CB4aA41", "privateKey": "0x696fb1e2444217e7be398c3dbe096a115e6202f4e2fa7ae2c8a220e64f939029", "pointType": 1 }, { "idx": 92, - "phone":"08201010002092", + "phone": "08201010002092", "address": "0x1A976a73C2E1d578d12C1d5490EA39Da032DED09", "privateKey": "0x163776f9e9f1a96c971ba998ba9db13a621f6b5bef56ed37544e102a004e93cf", "pointType": 1 }, { "idx": 93, - "phone":"08201010002093", + "phone": "08201010002093", "address": "0x274b22DA330f2888CA272b325E4B806BEE1020dD", "privateKey": "0x0faf1b2426d64b103aaf827ef79331838b486cd43b50c37b890c02be90245846", "pointType": 1 }, { "idx": 94, - "phone":"08201010002094", + "phone": "08201010002094", "address": "0xC6E444e95F5c0e1D08bD6BF696e7b7be78C52F0A", "privateKey": "0x3b5e7e810c6908d7629a3425252d3a4350b0c4c7ecdc4b070dc390c7a14d7ee3", "pointType": 1 }, { "idx": 95, - "phone":"08201010002095", + "phone": "08201010002095", "address": "0xBf71BE43744dE11ab907Cd437a3544988Bcd64E9", "privateKey": "0x40036472b731d1a288b47c7182b988d540bc63c32f1e362210d4c074c9e609bb", "pointType": 1 }, { "idx": 96, - "phone":"08201010002096", + "phone": "08201010002096", "address": "0x8FF6E213BF89DBad2ff139E3C9D07D66438c8cC0", "privateKey": "0x9aa24c5b22cddbe10ba0e587f9cf691490250e7b9168faa87c9c482abe8f10de", "pointType": 1 }, { "idx": 97, - "phone":"08201010002097", + "phone": "08201010002097", "address": "0x9CB046D582f5aF26e649e4657953523de0b5177A", "privateKey": "0x60e8ebd2860037d34b3afd6122235afdfd34d32950e1adc70e98b73ea1ba181b", "pointType": 1 }, { "idx": 98, - "phone":"08201010002098", + "phone": "08201010002098", "address": "0x24dd2E8A8571090fDA4D92a9d94995E651B65640", "privateKey": "0x7d3255042d6b870964d1a33b724cc9af9b3d8fa9e3572cec3046dd670e57f4e4", "pointType": 1 }, { "idx": 99, - "phone":"08201010002099", + "phone": "08201010002099", "address": "0x20eB9941Df5b95b1b1AfAc1193c6a075B6191563", "privateKey": "0x16541efcf7b3743f7d174d3daaa88ed32fdb2ba5495710e4859a34d00df29144", "pointType": 1 diff --git a/packages/faker/src/scheduler/DefaultScheduler.ts b/packages/faker/src/scheduler/DefaultScheduler.ts index 64135630..fca61ba3 100644 --- a/packages/faker/src/scheduler/DefaultScheduler.ts +++ b/packages/faker/src/scheduler/DefaultScheduler.ts @@ -8,7 +8,7 @@ import { ContractUtils } from "../utils/ContractUtils"; import { Utils } from "../utils/Utils"; import { Scheduler } from "./Scheduler"; -import { Ledger, PhoneLinkCollection, Token } from "../../typechain-types"; +import { Ledger, Token } from "../../typechain-types"; import { NonceManager } from "@ethersproject/experimental"; import { Signer, Wallet } from "ethers"; @@ -40,12 +40,6 @@ export class DefaultScheduler extends Scheduler { */ private _ledgerContract: Ledger | undefined; - /** - * 이메일 지갑주소 링크 컨트랙트 - * @private - */ - private _phoneLinkerContract: PhoneLinkCollection | undefined; - private _purchaseIdx: number = 0; private _users: IUserData[]; @@ -112,21 +106,6 @@ export class DefaultScheduler extends Scheduler { return this._ledgerContract; } - /** - * 이메일 지갑주소 링크 컨트랙트를 리턴한다. - * 컨트랙트의 객체가 생성되지 않았다면 컨트랙트 주소를 이용하여 컨트랙트 객체를 생성한 후 반환한다. - * @private - */ - private async getPhoneLinkerContract(): Promise { - if (this._phoneLinkerContract === undefined) { - const linkCollectionFactory = await hre.ethers.getContractFactory("PhoneLinkCollection"); - this._phoneLinkerContract = linkCollectionFactory.attach( - this._config.contracts.phoneLinkerAddress - ) as PhoneLinkCollection; - } - return this._phoneLinkerContract; - } - /*** * 서명자 * @private diff --git a/packages/faker/src/types/index.ts b/packages/faker/src/types/index.ts index 941e0f12..1f2df476 100644 --- a/packages/faker/src/types/index.ts +++ b/packages/faker/src/types/index.ts @@ -13,8 +13,11 @@ export interface IPurchaseData { export interface IShopData { shopId: string; + name: string; provideWaitTime: number; providePercent: number; + address: string; + privateKey: string; } export interface IUserData { diff --git a/packages/faker/src/utils/ContractUtils.ts b/packages/faker/src/utils/ContractUtils.ts index d80a2a82..1e147e06 100644 --- a/packages/faker/src/utils/ContractUtils.ts +++ b/packages/faker/src/utils/ContractUtils.ts @@ -57,33 +57,45 @@ export class ContractUtils { return signer.signMessage(message); } - public static async signPayment( - signer: Signer, + public static getPaymentMessage( + address: string, purchaseId: string, amount: BigNumberish, - userEmail: string, + currency: string, shopId: string, nonce: BigNumberish - ): Promise { + ): Uint8Array { const encodedResult = hre.ethers.utils.defaultAbiCoder.encode( - ["string", "uint256", "bytes32", "string", "address", "uint256"], - [purchaseId, amount, userEmail, shopId, await signer.getAddress(), nonce] + ["string", "uint256", "string", "bytes32", "address", "uint256"], + [purchaseId, amount, currency, shopId, address, nonce] ); - const message = arrayify(hre.ethers.utils.keccak256(encodedResult)); - return signer.signMessage(message); + return arrayify(hre.ethers.utils.keccak256(encodedResult)); } - public static async signExchange( + public static async signPayment( signer: Signer, - userEmail: string, + purchaseId: string, amount: BigNumberish, + currency: string, + shopId: string, nonce: BigNumberish ): Promise { - const encodedResult = hre.ethers.utils.defaultAbiCoder.encode( - ["bytes32", "uint256", "address", "uint256"], - [userEmail, amount, await signer.getAddress(), nonce] + const message = ContractUtils.getPaymentMessage( + await signer.getAddress(), + purchaseId, + amount, + currency, + shopId, + nonce ); - const message = arrayify(hre.ethers.utils.keccak256(encodedResult)); return signer.signMessage(message); } + + public static getShopId(name: string, account: string): string { + const encodedResult = hre.ethers.utils.defaultAbiCoder.encode( + ["string", "address", "bytes32"], + [name, account, crypto.randomBytes(32)] + ); + return hre.ethers.utils.keccak256(encodedResult); + } } diff --git a/packages/relay/src/routers/DefaultRouter.ts b/packages/relay/src/routers/DefaultRouter.ts index cff7cb1c..d368368b 100644 --- a/packages/relay/src/routers/DefaultRouter.ts +++ b/packages/relay/src/routers/DefaultRouter.ts @@ -185,7 +185,9 @@ export class DefaultRouter { body("purchaseId").exists(), body("amount").custom(Validation.isAmount), body("currency").exists(), - body("shopId").exists(), + body("shopId") + .exists() + .matches(/^(0x)[0-9a-f]{64}$/i), body("account").exists().isEthereumAddress(), body("signature") .exists() @@ -201,7 +203,9 @@ export class DefaultRouter { body("purchaseId").exists(), body("amount").custom(Validation.isAmount), body("currency").exists(), - body("shopId").exists(), + body("shopId") + .exists() + .matches(/^(0x)[0-9a-f]{64}$/i), body("account").exists().isEthereumAddress(), body("signature") .exists() diff --git a/packages/relay/src/utils/ContractUtils.ts b/packages/relay/src/utils/ContractUtils.ts index 74dc2907..6812246b 100644 --- a/packages/relay/src/utils/ContractUtils.ts +++ b/packages/relay/src/utils/ContractUtils.ts @@ -118,7 +118,7 @@ export class ContractUtils { nonce: BigNumberish ): Uint8Array { const encodedResult = hre.ethers.utils.defaultAbiCoder.encode( - ["string", "uint256", "string", "string", "address", "uint256"], + ["string", "uint256", "string", "bytes32", "address", "uint256"], [purchaseId, amount, currency, shopId, address, nonce] ); return arrayify(hre.ethers.utils.keccak256(encodedResult)); @@ -219,4 +219,12 @@ export class ContractUtils { } return res.toLowerCase() === account.toLowerCase(); } + + public static getShopId(name: string, account: string): string { + const encodedResult = hre.ethers.utils.defaultAbiCoder.encode( + ["string", "address", "bytes32"], + [name, account, crypto.randomBytes(32)] + ); + return hre.ethers.utils.keccak256(encodedResult); + } } diff --git a/packages/relay/test/Endpoints.test.ts b/packages/relay/test/Endpoints.test.ts index 437f8e4f..0164eb7e 100644 --- a/packages/relay/test/Endpoints.test.ts +++ b/packages/relay/test/Endpoints.test.ts @@ -35,6 +35,8 @@ describe("Test of Server", function () { const [ deployer, foundation, + settlements, + fee, validator1, validator2, validator3, @@ -46,17 +48,18 @@ describe("Test of Server", function () { relay3, relay4, relay5, + shop1, + shop2, + shop3, + shop4, + shop5, ] = provider.getWallets(); const validators = [validator1, validator2, validator3]; const linkValidators = [validator1]; const users = [user1, user2, user3]; - const phoneHashes: string[] = [ - ContractUtils.getPhoneHash("08201012341001"), - ContractUtils.getPhoneHash("08201012341002"), - ContractUtils.getPhoneHash("08201012341003"), - ContractUtils.getPhoneHash("08201012341004"), - ]; + const shopWallets = [shop1, shop2, shop3, shop4, shop5]; + let validatorContract: ValidatorCollection; let tokenContract: Token; let ledgerContract: Ledger; @@ -124,9 +127,7 @@ describe("Test of Server", function () { const deployShopCollection = async () => { const shopCollectionFactory = await hre.ethers.getContractFactory("ShopCollection"); - shopCollection = (await shopCollectionFactory - .connect(deployer) - .deploy(validatorContract.address)) as ShopCollection; + shopCollection = (await shopCollectionFactory.connect(deployer).deploy()) as ShopCollection; await shopCollection.deployed(); await shopCollection.deployTransaction.wait(); }; @@ -138,6 +139,7 @@ describe("Test of Server", function () { .deploy( foundation.address, foundation.address, + fee.address, tokenContract.address, validatorContract.address, linkCollectionContract.address, @@ -167,41 +169,47 @@ describe("Test of Server", function () { interface IShopData { shopId: string; + name: string; provideWaitTime: number; providePercent: number; - phone: string; + wallet: Wallet; } const shopData: IShopData[] = [ { shopId: "F000100", + name: "Shop1", provideWaitTime: 0, - providePercent: 1, - phone: "08201020001000", + providePercent: 10, + wallet: shopWallets[0], }, { shopId: "F000200", + name: "Shop2", provideWaitTime: 0, - providePercent: 1, - phone: "08201020001001", + providePercent: 20, + wallet: shopWallets[1], }, { shopId: "F000300", + name: "Shop3", provideWaitTime: 0, - providePercent: 1, - phone: "08201020001002", + providePercent: 20, + wallet: shopWallets[2], }, { shopId: "F000400", + name: "Shop4", provideWaitTime: 0, - providePercent: 1, - phone: "08201020001003", + providePercent: 20, + wallet: shopWallets[3], }, { shopId: "F000500", + name: "Shop5", provideWaitTime: 0, - providePercent: 1, - phone: "08201020001004", + providePercent: 20, + wallet: shopWallets[4], }, ]; @@ -244,6 +252,12 @@ describe("Test of Server", function () { } context("Test token & point relay endpoints", () => { + before("Set Shop ID", async () => { + for (const elem of shopData) { + elem.shopId = ContractUtils.getShopId(elem.name, elem.wallet.address); + } + }); + before("Deploy", async () => { await deployAllContract(); }); @@ -286,19 +300,38 @@ describe("Test of Server", function () { context("Prepare shop data", () => { it("Add Shop Data", async () => { for (const elem of shopData) { - const phoneHash = ContractUtils.getPhoneHash(elem.phone); await expect( shopCollection - .connect(validator1) - .add(elem.shopId, elem.provideWaitTime, elem.providePercent, phoneHash) + .connect(elem.wallet) + .add(elem.shopId, elem.name, elem.provideWaitTime, elem.providePercent) ) .to.emit(shopCollection, "AddedShop") - .withArgs(elem.shopId, elem.provideWaitTime, elem.providePercent, phoneHash); + .withNamedArgs({ + shopId: elem.shopId, + name: elem.name, + provideWaitTime: elem.provideWaitTime, + providePercent: elem.providePercent, + account: elem.wallet.address, + }); } expect(await shopCollection.shopsLength()).to.equal(shopData.length); }); }); + context("Prepare foundation's asset", () => { + it("Deposit foundation's token", async () => { + await tokenContract.connect(deployer).transfer(foundation.address, assetAmount.value); + await tokenContract.connect(foundation).approve(ledgerContract.address, assetAmount.value); + await expect(ledgerContract.connect(foundation).deposit(assetAmount.value)) + .to.emit(ledgerContract, "Deposited") + .withNamedArgs({ + account: foundation.address, + depositAmount: assetAmount.value, + balanceToken: assetAmount.value, + }); + }); + }); + context("Save Purchase Data", () => { const purchase: IPurchaseData = { purchaseId: "P000001", @@ -614,14 +647,19 @@ describe("Test of Server", function () { context("Prepare shop data", () => { it("Add Shop Data", async () => { for (const elem of shopData) { - const phoneHash = ContractUtils.getPhoneHash(elem.phone); await expect( shopCollection - .connect(validator1) - .add(elem.shopId, elem.provideWaitTime, elem.providePercent, phoneHash) + .connect(elem.wallet) + .add(elem.shopId, elem.name, elem.provideWaitTime, elem.providePercent) ) .to.emit(shopCollection, "AddedShop") - .withArgs(elem.shopId, elem.provideWaitTime, elem.providePercent, phoneHash); + .withNamedArgs({ + shopId: elem.shopId, + name: elem.name, + provideWaitTime: elem.provideWaitTime, + providePercent: elem.providePercent, + account: elem.wallet.address, + }); } expect(await shopCollection.shopsLength()).to.equal(shopData.length); }); diff --git a/packages/subgraph/generated/Ledger/Ledger.ts b/packages/subgraph/generated/Ledger/Ledger.ts index 068f473b..8617e87a 100644 --- a/packages/subgraph/generated/Ledger/Ledger.ts +++ b/packages/subgraph/generated/Ledger/Ledger.ts @@ -121,21 +121,29 @@ export class PaidPoint__Params { return this._event.parameters[2].value.toBigInt(); } - get balancePoint(): BigInt { + get fee(): BigInt { return this._event.parameters[3].value.toBigInt(); } - get purchaseId(): string { - return this._event.parameters[4].value.toString(); + get feeValue(): BigInt { + return this._event.parameters[4].value.toBigInt(); } - get purchaseAmount(): BigInt { + get balancePoint(): BigInt { return this._event.parameters[5].value.toBigInt(); } - get shopId(): string { + get purchaseId(): string { return this._event.parameters[6].value.toString(); } + + get purchaseAmount(): BigInt { + return this._event.parameters[7].value.toBigInt(); + } + + get shopId(): Bytes { + return this._event.parameters[8].value.toBytes(); + } } export class PaidToken extends ethereum.Event { @@ -163,21 +171,29 @@ export class PaidToken__Params { return this._event.parameters[2].value.toBigInt(); } - get balanceToken(): BigInt { + get fee(): BigInt { return this._event.parameters[3].value.toBigInt(); } - get purchaseId(): string { - return this._event.parameters[4].value.toString(); + get feeValue(): BigInt { + return this._event.parameters[4].value.toBigInt(); } - get purchaseAmount(): BigInt { + get balanceToken(): BigInt { return this._event.parameters[5].value.toBigInt(); } - get shopId(): string { + get purchaseId(): string { return this._event.parameters[6].value.toString(); } + + get purchaseAmount(): BigInt { + return this._event.parameters[7].value.toBigInt(); + } + + get shopId(): Bytes { + return this._event.parameters[8].value.toBytes(); + } } export class ProvidedPoint extends ethereum.Event { @@ -213,8 +229,8 @@ export class ProvidedPoint__Params { return this._event.parameters[4].value.toString(); } - get shopId(): string { - return this._event.parameters[5].value.toString(); + get shopId(): Bytes { + return this._event.parameters[5].value.toBytes(); } } @@ -251,8 +267,8 @@ export class ProvidedToken__Params { return this._event.parameters[4].value.toString(); } - get shopId(): string { - return this._event.parameters[5].value.toString(); + get shopId(): Bytes { + return this._event.parameters[5].value.toBytes(); } } @@ -273,8 +289,8 @@ export class ProvidedTokenForSettlement__Params { return this._event.parameters[0].value.toAddress(); } - get shopId(): string { - return this._event.parameters[1].value.toString(); + get shopId(): Bytes { + return this._event.parameters[1].value.toBytes(); } get providedAmountPoint(): BigInt { @@ -331,8 +347,8 @@ export class ProvidedUnPayablePoint__Params { return this._event.parameters[4].value.toString(); } - get shopId(): string { - return this._event.parameters[5].value.toString(); + get shopId(): Bytes { + return this._event.parameters[5].value.toBytes(); } } @@ -365,8 +381,8 @@ export class SavedPurchase__Params { return this._event.parameters[3].value.toString(); } - get shopId(): string { - return this._event.parameters[4].value.toString(); + get shopId(): Bytes { + return this._event.parameters[4].value.toBytes(); } get method(): BigInt { @@ -429,8 +445,8 @@ export class Ledger__purchaseOfResultValue0Struct extends ethereum.Tuple { return this[3].toString(); } - get shopId(): string { - return this[4].toString(); + get shopId(): Bytes { + return this[4].toBytes(); } get method(): BigInt { @@ -470,6 +486,21 @@ export class Ledger extends ethereum.SmartContract { return ethereum.CallResult.fromValue(value[0].toBytes()); } + MAX_FEE(): BigInt { + let result = super.call("MAX_FEE", "MAX_FEE():(uint32)", []); + + return result[0].toBigInt(); + } + + try_MAX_FEE(): ethereum.CallResult { + let result = super.tryCall("MAX_FEE", "MAX_FEE():(uint32)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + NULL(): Bytes { let result = super.call("NULL", "NULL():(bytes32)", []); @@ -527,6 +558,36 @@ export class Ledger extends ethereum.SmartContract { return ethereum.CallResult.fromValue(value[0].toAddress()); } + fee(): BigInt { + let result = super.call("fee", "fee():(uint32)", []); + + return result[0].toBigInt(); + } + + try_fee(): ethereum.CallResult { + let result = super.tryCall("fee", "fee():(uint32)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + feeAccount(): Address { + let result = super.call("feeAccount", "feeAccount():(address)", []); + + return result[0].toAddress(); + } + + try_feeAccount(): ethereum.CallResult
{ + let result = super.tryCall("feeAccount", "feeAccount():(address)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + foundationAccount(): Address { let result = super.call( "foundationAccount", @@ -658,7 +719,7 @@ export class Ledger extends ethereum.SmartContract { purchaseOf(_purchaseId: string): Ledger__purchaseOfResultValue0Struct { let result = super.call( "purchaseOf", - "purchaseOf(string):((string,uint256,uint256,string,string,uint32,address,bytes32))", + "purchaseOf(string):((string,uint256,uint256,string,bytes32,uint32,address,bytes32))", [ethereum.Value.fromString(_purchaseId)] ); @@ -672,7 +733,7 @@ export class Ledger extends ethereum.SmartContract { ): ethereum.CallResult { let result = super.tryCall( "purchaseOf", - "purchaseOf(string):((string,uint256,uint256,string,string,uint32,address,bytes32))", + "purchaseOf(string):((string,uint256,uint256,string,bytes32,uint32,address,bytes32))", [ethereum.Value.fromString(_purchaseId)] ); if (result.reverted) { @@ -863,25 +924,29 @@ export class ConstructorCall__Inputs { return this._call.inputValues[1].value.toAddress(); } - get _tokenAddress(): Address { + get _feeAccount(): Address { return this._call.inputValues[2].value.toAddress(); } - get _validatorAddress(): Address { + get _tokenAddress(): Address { return this._call.inputValues[3].value.toAddress(); } - get _linkCollectionAddress(): Address { + get _validatorAddress(): Address { return this._call.inputValues[4].value.toAddress(); } - get _currencyRateAddress(): Address { + get _linkCollectionAddress(): Address { return this._call.inputValues[5].value.toAddress(); } - get _shopCollectionAddress(): Address { + get _currencyRateAddress(): Address { return this._call.inputValues[6].value.toAddress(); } + + get _shopCollectionAddress(): Address { + return this._call.inputValues[7].value.toAddress(); + } } export class ConstructorCall__Outputs { @@ -977,8 +1042,8 @@ export class PayPointCall__Inputs { this._call = call; } - get data(): PayPointCallDataStruct { - return changetype( + get _data(): PayPointCall_dataStruct { + return changetype( this._call.inputValues[0].value.toTuple() ); } @@ -992,7 +1057,7 @@ export class PayPointCall__Outputs { } } -export class PayPointCallDataStruct extends ethereum.Tuple { +export class PayPointCall_dataStruct extends ethereum.Tuple { get purchaseId(): string { return this[0].toString(); } @@ -1005,8 +1070,8 @@ export class PayPointCallDataStruct extends ethereum.Tuple { return this[2].toString(); } - get shopId(): string { - return this[3].toString(); + get shopId(): Bytes { + return this[3].toBytes(); } get account(): Address { @@ -1035,8 +1100,8 @@ export class PayTokenCall__Inputs { this._call = call; } - get data(): PayTokenCallDataStruct { - return changetype( + get _data(): PayTokenCall_dataStruct { + return changetype( this._call.inputValues[0].value.toTuple() ); } @@ -1050,7 +1115,7 @@ export class PayTokenCall__Outputs { } } -export class PayTokenCallDataStruct extends ethereum.Tuple { +export class PayTokenCall_dataStruct extends ethereum.Tuple { get purchaseId(): string { return this[0].toString(); } @@ -1063,8 +1128,8 @@ export class PayTokenCallDataStruct extends ethereum.Tuple { return this[2].toString(); } - get shopId(): string { - return this[3].toString(); + get shopId(): Bytes { + return this[3].toBytes(); } get account(): Address { @@ -1125,8 +1190,8 @@ export class SavePurchaseCallDataStruct extends ethereum.Tuple { return this[3].toString(); } - get shopId(): string { - return this[4].toString(); + get shopId(): Bytes { + return this[4].toBytes(); } get method(): BigInt { @@ -1142,6 +1207,36 @@ export class SavePurchaseCallDataStruct extends ethereum.Tuple { } } +export class SetFeeCall extends ethereum.Call { + get inputs(): SetFeeCall__Inputs { + return new SetFeeCall__Inputs(this); + } + + get outputs(): SetFeeCall__Outputs { + return new SetFeeCall__Outputs(this); + } +} + +export class SetFeeCall__Inputs { + _call: SetFeeCall; + + constructor(call: SetFeeCall) { + this._call = call; + } + + get _fee(): BigInt { + return this._call.inputValues[0].value.toBigInt(); + } +} + +export class SetFeeCall__Outputs { + _call: SetFeeCall; + + constructor(call: SetFeeCall) { + this._call = call; + } +} + export class SetPointTypeCall extends ethereum.Call { get inputs(): SetPointTypeCall__Inputs { return new SetPointTypeCall__Inputs(this); diff --git a/packages/subgraph/generated/ShopCollection/ShopCollection.ts b/packages/subgraph/generated/ShopCollection/ShopCollection.ts index 3238db51..37196135 100644 --- a/packages/subgraph/generated/ShopCollection/ShopCollection.ts +++ b/packages/subgraph/generated/ShopCollection/ShopCollection.ts @@ -23,20 +23,50 @@ export class AddedShop__Params { this._event = event; } - get shopId(): string { - return this._event.parameters[0].value.toString(); + get shopId(): Bytes { + return this._event.parameters[0].value.toBytes(); + } + + get name(): string { + return this._event.parameters[1].value.toString(); } get provideWaitTime(): BigInt { - return this._event.parameters[1].value.toBigInt(); + return this._event.parameters[2].value.toBigInt(); } get providePercent(): BigInt { - return this._event.parameters[2].value.toBigInt(); + return this._event.parameters[3].value.toBigInt(); + } + + get account(): Address { + return this._event.parameters[4].value.toAddress(); + } +} + +export class ClosedWithdrawal extends ethereum.Event { + get params(): ClosedWithdrawal__Params { + return new ClosedWithdrawal__Params(this); + } +} + +export class ClosedWithdrawal__Params { + _event: ClosedWithdrawal; + + constructor(event: ClosedWithdrawal) { + this._event = event; + } + + get shopId(): Bytes { + return this._event.parameters[0].value.toBytes(); } - get phone(): Bytes { - return this._event.parameters[3].value.toBytes(); + get amount(): BigInt { + return this._event.parameters[1].value.toBigInt(); + } + + get account(): Address { + return this._event.parameters[2].value.toAddress(); } } @@ -53,8 +83,8 @@ export class IncreasedProvidedPoint__Params { this._event = event; } - get shopId(): string { - return this._event.parameters[0].value.toString(); + get shopId(): Bytes { + return this._event.parameters[0].value.toBytes(); } get increase(): BigInt { @@ -83,8 +113,8 @@ export class IncreasedSettledPoint__Params { this._event = event; } - get shopId(): string { - return this._event.parameters[0].value.toString(); + get shopId(): Bytes { + return this._event.parameters[0].value.toBytes(); } get increase(): BigInt { @@ -113,8 +143,8 @@ export class IncreasedUsedPoint__Params { this._event = event; } - get shopId(): string { - return this._event.parameters[0].value.toString(); + get shopId(): Bytes { + return this._event.parameters[0].value.toBytes(); } get increase(): BigInt { @@ -130,122 +160,153 @@ export class IncreasedUsedPoint__Params { } } -export class UpdatedShop extends ethereum.Event { - get params(): UpdatedShop__Params { - return new UpdatedShop__Params(this); +export class OpenedWithdrawal extends ethereum.Event { + get params(): OpenedWithdrawal__Params { + return new OpenedWithdrawal__Params(this); } } -export class UpdatedShop__Params { - _event: UpdatedShop; +export class OpenedWithdrawal__Params { + _event: OpenedWithdrawal; - constructor(event: UpdatedShop) { + constructor(event: OpenedWithdrawal) { this._event = event; } - get shopId(): string { - return this._event.parameters[0].value.toString(); + get shopId(): Bytes { + return this._event.parameters[0].value.toBytes(); } - get provideWaitTime(): BigInt { + get amount(): BigInt { return this._event.parameters[1].value.toBigInt(); } - get providePercent(): BigInt { - return this._event.parameters[2].value.toBigInt(); + get account(): Address { + return this._event.parameters[2].value.toAddress(); } +} - get phone(): Bytes { - return this._event.parameters[3].value.toBytes(); +export class RemovedShop extends ethereum.Event { + get params(): RemovedShop__Params { + return new RemovedShop__Params(this); } } -export class ShopCollection__shopByPhoneOfResultValue0Struct extends ethereum.Tuple { - get shopId(): string { - return this[0].toString(); +export class RemovedShop__Params { + _event: RemovedShop; + + constructor(event: RemovedShop) { + this._event = event; } - get provideWaitTime(): BigInt { - return this[1].toBigInt(); + get shopId(): Bytes { + return this._event.parameters[0].value.toBytes(); } +} - get providePercent(): BigInt { - return this[2].toBigInt(); +export class UpdatedShop extends ethereum.Event { + get params(): UpdatedShop__Params { + return new UpdatedShop__Params(this); } +} - get phone(): Bytes { - return this[3].toBytes(); +export class UpdatedShop__Params { + _event: UpdatedShop; + + constructor(event: UpdatedShop) { + this._event = event; } - get providedPoint(): BigInt { - return this[4].toBigInt(); + get shopId(): Bytes { + return this._event.parameters[0].value.toBytes(); } - get usedPoint(): BigInt { - return this[5].toBigInt(); + get name(): string { + return this._event.parameters[1].value.toString(); } - get settledPoint(): BigInt { - return this[6].toBigInt(); + get provideWaitTime(): BigInt { + return this._event.parameters[2].value.toBigInt(); } - get status(): i32 { - return this[7].toI32(); + get providePercent(): BigInt { + return this._event.parameters[3].value.toBigInt(); + } + + get account(): Address { + return this._event.parameters[4].value.toAddress(); } } export class ShopCollection__shopOfResultValue0Struct extends ethereum.Tuple { - get shopId(): string { - return this[0].toString(); + get shopId(): Bytes { + return this[0].toBytes(); + } + + get name(): string { + return this[1].toString(); } get provideWaitTime(): BigInt { - return this[1].toBigInt(); + return this[2].toBigInt(); } get providePercent(): BigInt { - return this[2].toBigInt(); + return this[3].toBigInt(); } - get phone(): Bytes { - return this[3].toBytes(); + get account(): Address { + return this[4].toAddress(); } get providedPoint(): BigInt { - return this[4].toBigInt(); + return this[5].toBigInt(); } get usedPoint(): BigInt { - return this[5].toBigInt(); + return this[6].toBigInt(); } get settledPoint(): BigInt { - return this[6].toBigInt(); + return this[7].toBigInt(); + } + + get withdrawnPoint(): BigInt { + return this[8].toBigInt(); } get status(): i32 { - return this[7].toI32(); + return this[9].toI32(); } -} -export class ShopCollection extends ethereum.SmartContract { - static bind(address: Address): ShopCollection { - return new ShopCollection("ShopCollection", address); + get withdrawData(): ShopCollection__shopOfResultValue0WithdrawDataStruct { + return changetype( + this[10].toTuple() + ); } - NULL(): Bytes { - let result = super.call("NULL", "NULL():(bytes32)", []); + get itemIndex(): BigInt { + return this[11].toBigInt(); + } - return result[0].toBytes(); + get accountIndex(): BigInt { + return this[12].toBigInt(); } +} - try_NULL(): ethereum.CallResult { - let result = super.tryCall("NULL", "NULL():(bytes32)", []); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBytes()); +export class ShopCollection__shopOfResultValue0WithdrawDataStruct extends ethereum.Tuple { + get amount(): BigInt { + return this[0].toBigInt(); + } + + get status(): i32 { + return this[1].toI32(); + } +} + +export class ShopCollection extends ethereum.SmartContract { + static bind(address: Address): ShopCollection { + return new ShopCollection("ShopCollection", address); } deployer(): Address { @@ -263,21 +324,21 @@ export class ShopCollection extends ethereum.SmartContract { return ethereum.CallResult.fromValue(value[0].toAddress()); } - getSettlementPoint(_shopId: string): BigInt { + getSettlementPoint(_shopId: Bytes): BigInt { let result = super.call( "getSettlementPoint", - "getSettlementPoint(string):(uint256)", - [ethereum.Value.fromString(_shopId)] + "getSettlementPoint(bytes32):(uint256)", + [ethereum.Value.fromFixedBytes(_shopId)] ); return result[0].toBigInt(); } - try_getSettlementPoint(_shopId: string): ethereum.CallResult { + try_getSettlementPoint(_shopId: Bytes): ethereum.CallResult { let result = super.tryCall( "getSettlementPoint", - "getSettlementPoint(string):(uint256)", - [ethereum.Value.fromString(_shopId)] + "getSettlementPoint(bytes32):(uint256)", + [ethereum.Value.fromFixedBytes(_shopId)] ); if (result.reverted) { return new ethereum.CallResult(); @@ -286,82 +347,70 @@ export class ShopCollection extends ethereum.SmartContract { return ethereum.CallResult.fromValue(value[0].toBigInt()); } - ledgerAddress(): Address { - let result = super.call("ledgerAddress", "ledgerAddress():(address)", []); + isAvailableId(_shopId: Bytes): boolean { + let result = super.call("isAvailableId", "isAvailableId(bytes32):(bool)", [ + ethereum.Value.fromFixedBytes(_shopId) + ]); - return result[0].toAddress(); + return result[0].toBoolean(); } - try_ledgerAddress(): ethereum.CallResult
{ + try_isAvailableId(_shopId: Bytes): ethereum.CallResult { let result = super.tryCall( - "ledgerAddress", - "ledgerAddress():(address)", - [] + "isAvailableId", + "isAvailableId(bytes32):(bool)", + [ethereum.Value.fromFixedBytes(_shopId)] ); if (result.reverted) { return new ethereum.CallResult(); } let value = result.value; - return ethereum.CallResult.fromValue(value[0].toAddress()); + return ethereum.CallResult.fromValue(value[0].toBoolean()); } - shopByPhoneOf( - _phone: Bytes - ): ShopCollection__shopByPhoneOfResultValue0Struct { - let result = super.call( - "shopByPhoneOf", - "shopByPhoneOf(bytes32):((string,uint256,uint256,bytes32,uint256,uint256,uint256,uint8))", - [ethereum.Value.fromFixedBytes(_phone)] - ); + ledgerAddress(): Address { + let result = super.call("ledgerAddress", "ledgerAddress():(address)", []); - return changetype( - result[0].toTuple() - ); + return result[0].toAddress(); } - try_shopByPhoneOf( - _phone: Bytes - ): ethereum.CallResult { + try_ledgerAddress(): ethereum.CallResult
{ let result = super.tryCall( - "shopByPhoneOf", - "shopByPhoneOf(bytes32):((string,uint256,uint256,bytes32,uint256,uint256,uint256,uint8))", - [ethereum.Value.fromFixedBytes(_phone)] + "ledgerAddress", + "ledgerAddress():(address)", + [] ); if (result.reverted) { return new ethereum.CallResult(); } let value = result.value; - return ethereum.CallResult.fromValue( - changetype( - value[0].toTuple() - ) - ); + return ethereum.CallResult.fromValue(value[0].toAddress()); } - shopIdOf(_idx: BigInt): string { - let result = super.call("shopIdOf", "shopIdOf(uint256):(string)", [ + shopIdOf(_idx: BigInt): Bytes { + let result = super.call("shopIdOf", "shopIdOf(uint256):(bytes32)", [ ethereum.Value.fromUnsignedBigInt(_idx) ]); - return result[0].toString(); + return result[0].toBytes(); } - try_shopIdOf(_idx: BigInt): ethereum.CallResult { - let result = super.tryCall("shopIdOf", "shopIdOf(uint256):(string)", [ + try_shopIdOf(_idx: BigInt): ethereum.CallResult { + let result = super.tryCall("shopIdOf", "shopIdOf(uint256):(bytes32)", [ ethereum.Value.fromUnsignedBigInt(_idx) ]); if (result.reverted) { return new ethereum.CallResult(); } let value = result.value; - return ethereum.CallResult.fromValue(value[0].toString()); + return ethereum.CallResult.fromValue(value[0].toBytes()); } - shopOf(_shopId: string): ShopCollection__shopOfResultValue0Struct { + shopOf(_shopId: Bytes): ShopCollection__shopOfResultValue0Struct { let result = super.call( "shopOf", - "shopOf(string):((string,uint256,uint256,bytes32,uint256,uint256,uint256,uint8))", - [ethereum.Value.fromString(_shopId)] + "shopOf(bytes32):((bytes32,string,uint256,uint256,address,uint256,uint256,uint256,uint256,uint8,(uint256,uint8),uint256,uint256))", + [ethereum.Value.fromFixedBytes(_shopId)] ); return changetype( @@ -370,12 +419,12 @@ export class ShopCollection extends ethereum.SmartContract { } try_shopOf( - _shopId: string + _shopId: Bytes ): ethereum.CallResult { let result = super.tryCall( "shopOf", - "shopOf(string):((string,uint256,uint256,bytes32,uint256,uint256,uint256,uint8))", - [ethereum.Value.fromString(_shopId)] + "shopOf(bytes32):((bytes32,string,uint256,uint256,address,uint256,uint256,uint256,uint256,uint8,(uint256,uint8),uint256,uint256))", + [ethereum.Value.fromFixedBytes(_shopId)] ); if (result.reverted) { return new ethereum.CallResult(); @@ -401,27 +450,46 @@ export class ShopCollection extends ethereum.SmartContract { return ethereum.CallResult.fromValue(value[0].toBigInt()); } - validatorAddress(): Address { + shopsOf(_account: Address): Array { + let result = super.call("shopsOf", "shopsOf(address):(bytes32[])", [ + ethereum.Value.fromAddress(_account) + ]); + + return result[0].toBytesArray(); + } + + try_shopsOf(_account: Address): ethereum.CallResult> { + let result = super.tryCall("shopsOf", "shopsOf(address):(bytes32[])", [ + ethereum.Value.fromAddress(_account) + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBytesArray()); + } + + withdrawableOf(_shopId: Bytes): BigInt { let result = super.call( - "validatorAddress", - "validatorAddress():(address)", - [] + "withdrawableOf", + "withdrawableOf(bytes32):(uint256)", + [ethereum.Value.fromFixedBytes(_shopId)] ); - return result[0].toAddress(); + return result[0].toBigInt(); } - try_validatorAddress(): ethereum.CallResult
{ + try_withdrawableOf(_shopId: Bytes): ethereum.CallResult { let result = super.tryCall( - "validatorAddress", - "validatorAddress():(address)", - [] + "withdrawableOf", + "withdrawableOf(bytes32):(uint256)", + [ethereum.Value.fromFixedBytes(_shopId)] ); if (result.reverted) { return new ethereum.CallResult(); } let value = result.value; - return ethereum.CallResult.fromValue(value[0].toAddress()); + return ethereum.CallResult.fromValue(value[0].toBigInt()); } } @@ -441,10 +509,6 @@ export class ConstructorCall__Inputs { constructor(call: ConstructorCall) { this._call = call; } - - get _validatorAddress(): Address { - return this._call.inputValues[0].value.toAddress(); - } } export class ConstructorCall__Outputs { @@ -472,20 +536,20 @@ export class AddCall__Inputs { this._call = call; } - get _shopId(): string { - return this._call.inputValues[0].value.toString(); + get _shopId(): Bytes { + return this._call.inputValues[0].value.toBytes(); } - get _provideWaitTime(): BigInt { - return this._call.inputValues[1].value.toBigInt(); + get _name(): string { + return this._call.inputValues[1].value.toString(); } - get _providePercent(): BigInt { + get _provideWaitTime(): BigInt { return this._call.inputValues[2].value.toBigInt(); } - get _phone(): Bytes { - return this._call.inputValues[3].value.toBytes(); + get _providePercent(): BigInt { + return this._call.inputValues[3].value.toBigInt(); } } @@ -514,8 +578,8 @@ export class AddProvidedPointCall__Inputs { this._call = call; } - get _shopId(): string { - return this._call.inputValues[0].value.toString(); + get _shopId(): Bytes { + return this._call.inputValues[0].value.toBytes(); } get _amount(): BigInt { @@ -552,8 +616,8 @@ export class AddSettledPointCall__Inputs { this._call = call; } - get _shopId(): string { - return this._call.inputValues[0].value.toString(); + get _shopId(): Bytes { + return this._call.inputValues[0].value.toBytes(); } get _amount(): BigInt { @@ -590,8 +654,8 @@ export class AddUsedPointCall__Inputs { this._call = call; } - get _shopId(): string { - return this._call.inputValues[0].value.toString(); + get _shopId(): Bytes { + return this._call.inputValues[0].value.toBytes(); } get _amount(): BigInt { @@ -611,6 +675,100 @@ export class AddUsedPointCall__Outputs { } } +export class CloseWithdrawalCall extends ethereum.Call { + get inputs(): CloseWithdrawalCall__Inputs { + return new CloseWithdrawalCall__Inputs(this); + } + + get outputs(): CloseWithdrawalCall__Outputs { + return new CloseWithdrawalCall__Outputs(this); + } +} + +export class CloseWithdrawalCall__Inputs { + _call: CloseWithdrawalCall; + + constructor(call: CloseWithdrawalCall) { + this._call = call; + } + + get _shopId(): Bytes { + return this._call.inputValues[0].value.toBytes(); + } +} + +export class CloseWithdrawalCall__Outputs { + _call: CloseWithdrawalCall; + + constructor(call: CloseWithdrawalCall) { + this._call = call; + } +} + +export class OpenWithdrawalCall extends ethereum.Call { + get inputs(): OpenWithdrawalCall__Inputs { + return new OpenWithdrawalCall__Inputs(this); + } + + get outputs(): OpenWithdrawalCall__Outputs { + return new OpenWithdrawalCall__Outputs(this); + } +} + +export class OpenWithdrawalCall__Inputs { + _call: OpenWithdrawalCall; + + constructor(call: OpenWithdrawalCall) { + this._call = call; + } + + get _shopId(): Bytes { + return this._call.inputValues[0].value.toBytes(); + } + + get _amount(): BigInt { + return this._call.inputValues[1].value.toBigInt(); + } +} + +export class OpenWithdrawalCall__Outputs { + _call: OpenWithdrawalCall; + + constructor(call: OpenWithdrawalCall) { + this._call = call; + } +} + +export class RemoveCall extends ethereum.Call { + get inputs(): RemoveCall__Inputs { + return new RemoveCall__Inputs(this); + } + + get outputs(): RemoveCall__Outputs { + return new RemoveCall__Outputs(this); + } +} + +export class RemoveCall__Inputs { + _call: RemoveCall; + + constructor(call: RemoveCall) { + this._call = call; + } + + get _shopId(): Bytes { + return this._call.inputValues[0].value.toBytes(); + } +} + +export class RemoveCall__Outputs { + _call: RemoveCall; + + constructor(call: RemoveCall) { + this._call = call; + } +} + export class SetLedgerAddressCall extends ethereum.Call { get inputs(): SetLedgerAddressCall__Inputs { return new SetLedgerAddressCall__Inputs(this); @@ -640,3 +798,45 @@ export class SetLedgerAddressCall__Outputs { this._call = call; } } + +export class UpdateCall extends ethereum.Call { + get inputs(): UpdateCall__Inputs { + return new UpdateCall__Inputs(this); + } + + get outputs(): UpdateCall__Outputs { + return new UpdateCall__Outputs(this); + } +} + +export class UpdateCall__Inputs { + _call: UpdateCall; + + constructor(call: UpdateCall) { + this._call = call; + } + + get _shopId(): Bytes { + return this._call.inputValues[0].value.toBytes(); + } + + get _name(): string { + return this._call.inputValues[1].value.toString(); + } + + get _provideWaitTime(): BigInt { + return this._call.inputValues[2].value.toBigInt(); + } + + get _providePercent(): BigInt { + return this._call.inputValues[3].value.toBigInt(); + } +} + +export class UpdateCall__Outputs { + _call: UpdateCall; + + constructor(call: UpdateCall) { + this._call = call; + } +} diff --git a/packages/subgraph/generated/schema.ts b/packages/subgraph/generated/schema.ts index 0ad3ea8f..d82aea10 100644 --- a/packages/subgraph/generated/schema.ts +++ b/packages/subgraph/generated/schema.ts @@ -488,6 +488,32 @@ export class PaidPoint extends Entity { this.set("value", Value.fromBigInt(value)); } + get fee(): BigInt { + let value = this.get("fee"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set fee(value: BigInt) { + this.set("fee", Value.fromBigInt(value)); + } + + get feeValue(): BigInt { + let value = this.get("feeValue"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set feeValue(value: BigInt) { + this.set("feeValue", Value.fromBigInt(value)); + } + get balancePoint(): BigInt { let value = this.get("balancePoint"); if (!value || value.kind == ValueKind.NULL) { @@ -527,17 +553,17 @@ export class PaidPoint extends Entity { this.set("purchaseAmount", Value.fromBigInt(value)); } - get shopId(): string { + get shopId(): Bytes { let value = this.get("shopId"); if (!value || value.kind == ValueKind.NULL) { throw new Error("Cannot return null for a required field."); } else { - return value.toString(); + return value.toBytes(); } } - set shopId(value: string) { - this.set("shopId", Value.fromString(value)); + set shopId(value: Bytes) { + this.set("shopId", Value.fromBytes(value)); } get blockNumber(): BigInt { @@ -662,6 +688,32 @@ export class PaidToken extends Entity { this.set("value", Value.fromBigInt(value)); } + get fee(): BigInt { + let value = this.get("fee"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set fee(value: BigInt) { + this.set("fee", Value.fromBigInt(value)); + } + + get feeValue(): BigInt { + let value = this.get("feeValue"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set feeValue(value: BigInt) { + this.set("feeValue", Value.fromBigInt(value)); + } + get balanceToken(): BigInt { let value = this.get("balanceToken"); if (!value || value.kind == ValueKind.NULL) { @@ -701,17 +753,17 @@ export class PaidToken extends Entity { this.set("purchaseAmount", Value.fromBigInt(value)); } - get shopId(): string { + get shopId(): Bytes { let value = this.get("shopId"); if (!value || value.kind == ValueKind.NULL) { throw new Error("Cannot return null for a required field."); } else { - return value.toString(); + return value.toBytes(); } } - set shopId(value: string) { - this.set("shopId", Value.fromString(value)); + set shopId(value: Bytes) { + this.set("shopId", Value.fromBytes(value)); } get blockNumber(): BigInt { @@ -862,17 +914,17 @@ export class ProvidedPoint extends Entity { this.set("purchaseId", Value.fromString(value)); } - get shopId(): string { + get shopId(): Bytes { let value = this.get("shopId"); if (!value || value.kind == ValueKind.NULL) { throw new Error("Cannot return null for a required field."); } else { - return value.toString(); + return value.toBytes(); } } - set shopId(value: string) { - this.set("shopId", Value.fromString(value)); + set shopId(value: Bytes) { + this.set("shopId", Value.fromBytes(value)); } get blockNumber(): BigInt { @@ -1023,17 +1075,17 @@ export class ProvidedToken extends Entity { this.set("purchaseId", Value.fromString(value)); } - get shopId(): string { + get shopId(): Bytes { let value = this.get("shopId"); if (!value || value.kind == ValueKind.NULL) { throw new Error("Cannot return null for a required field."); } else { - return value.toString(); + return value.toBytes(); } } - set shopId(value: string) { - this.set("shopId", Value.fromString(value)); + set shopId(value: Bytes) { + this.set("shopId", Value.fromBytes(value)); } get blockNumber(): BigInt { @@ -1135,17 +1187,17 @@ export class ProvidedTokenForSettlement extends Entity { this.set("account", Value.fromBytes(value)); } - get shopId(): string { + get shopId(): Bytes { let value = this.get("shopId"); if (!value || value.kind == ValueKind.NULL) { throw new Error("Cannot return null for a required field."); } else { - return value.toString(); + return value.toBytes(); } } - set shopId(value: string) { - this.set("shopId", Value.fromString(value)); + set shopId(value: Bytes) { + this.set("shopId", Value.fromBytes(value)); } get providedAmountPoint(): BigInt { @@ -1364,17 +1416,17 @@ export class ProvidedUnPayablePoint extends Entity { this.set("purchaseId", Value.fromString(value)); } - get shopId(): string { + get shopId(): Bytes { let value = this.get("shopId"); if (!value || value.kind == ValueKind.NULL) { throw new Error("Cannot return null for a required field."); } else { - return value.toString(); + return value.toBytes(); } } - set shopId(value: string) { - this.set("shopId", Value.fromString(value)); + set shopId(value: Bytes) { + this.set("shopId", Value.fromBytes(value)); } get blockNumber(): BigInt { @@ -1512,17 +1564,17 @@ export class SavedPurchase extends Entity { this.set("currency", Value.fromString(value)); } - get shopId(): string { + get shopId(): Bytes { let value = this.get("shopId"); if (!value || value.kind == ValueKind.NULL) { throw new Error("Cannot return null for a required field."); } else { - return value.toString(); + return value.toBytes(); } } - set shopId(value: string) { - this.set("shopId", Value.fromString(value)); + set shopId(value: Bytes) { + this.set("shopId", Value.fromBytes(value)); } get method(): BigInt { @@ -1903,21 +1955,17 @@ export class UserTradeHistory extends Entity { } } - get shopId(): string | null { + get shopId(): Bytes { let value = this.get("shopId"); if (!value || value.kind == ValueKind.NULL) { - return null; + throw new Error("Cannot return null for a required field."); } else { - return value.toString(); + return value.toBytes(); } } - set shopId(value: string | null) { - if (!value) { - this.unset("shopId"); - } else { - this.set("shopId", Value.fromString(value)); - } + set shopId(value: Bytes) { + this.set("shopId", Value.fromBytes(value)); } get blockNumber(): BigInt { @@ -2088,21 +2136,17 @@ export class UserUnPayableTradeHistory extends Entity { } } - get shopId(): string | null { + get shopId(): Bytes { let value = this.get("shopId"); if (!value || value.kind == ValueKind.NULL) { - return null; + throw new Error("Cannot return null for a required field."); } else { - return value.toString(); + return value.toBytes(); } } - set shopId(value: string | null) { - if (!value) { - this.unset("shopId"); - } else { - this.set("shopId", Value.fromString(value)); - } + set shopId(value: Bytes) { + this.set("shopId", Value.fromBytes(value)); } get blockNumber(): BigInt { @@ -2295,17 +2339,17 @@ export class ShopTradeHistory extends Entity { this.set("id", Value.fromBytes(value)); } - get shopId(): string { + get shopId(): Bytes { let value = this.get("shopId"); if (!value || value.kind == ValueKind.NULL) { throw new Error("Cannot return null for a required field."); } else { - return value.toString(); + return value.toBytes(); } } - set shopId(value: string) { - this.set("shopId", Value.fromString(value)); + set shopId(value: Bytes) { + this.set("shopId", Value.fromBytes(value)); } get purchaseId(): string | null { @@ -2469,6 +2513,19 @@ export class Shop extends Entity { this.set("id", Value.fromString(value)); } + get name(): string { + let value = this.get("name"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set name(value: string) { + this.set("name", Value.fromString(value)); + } + get provideWaitTime(): BigInt { let value = this.get("provideWaitTime"); if (!value || value.kind == ValueKind.NULL) { @@ -2495,8 +2552,8 @@ export class Shop extends Entity { this.set("providePercent", Value.fromBigInt(value)); } - get phone(): Bytes { - let value = this.get("phone"); + get account(): Bytes { + let value = this.get("account"); if (!value || value.kind == ValueKind.NULL) { throw new Error("Cannot return null for a required field."); } else { @@ -2504,8 +2561,21 @@ export class Shop extends Entity { } } - set phone(value: Bytes) { - this.set("phone", Value.fromBytes(value)); + set account(value: Bytes) { + this.set("account", Value.fromBytes(value)); + } + + get action(): string { + let value = this.get("action"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set action(value: string) { + this.set("action", Value.fromString(value)); } get providedPoint(): BigInt { diff --git a/packages/subgraph/manifest/subgraph.placeholder.yaml b/packages/subgraph/manifest/subgraph.placeholder.yaml index e1c912e2..81c09abe 100644 --- a/packages/subgraph/manifest/subgraph.placeholder.yaml +++ b/packages/subgraph/manifest/subgraph.placeholder.yaml @@ -37,19 +37,19 @@ dataSources: handler: handleChangedToPayablePoint - event: Deposited(address,uint256,uint256,uint256) handler: handleDeposited - - event: PaidPoint(address,uint256,uint256,uint256,string,uint256,string) + - event: PaidPoint(address,uint256,uint256,uint256,uint256,uint256,string,uint256,bytes32) handler: handlePaidPoint - - event: PaidToken(address,uint256,uint256,uint256,string,uint256,string) + - event: PaidToken(address,uint256,uint256,uint256,uint256,uint256,string,uint256,bytes32) handler: handlePaidToken - - event: ProvidedPoint(address,uint256,uint256,uint256,string,string) + - event: ProvidedPoint(address,uint256,uint256,uint256,string,bytes32) handler: handleProvidedPoint - - event: ProvidedToken(address,uint256,uint256,uint256,string,string) + - event: ProvidedToken(address,uint256,uint256,uint256,string,bytes32) handler: handleProvidedToken - - event: ProvidedTokenForSettlement(address,string,uint256,uint256,uint256,uint256,string) + - event: ProvidedTokenForSettlement(address,bytes32,uint256,uint256,uint256,uint256,string) handler: handleProvidedTokenForSettlement - - event: ProvidedUnPayablePoint(bytes32,uint256,uint256,uint256,string,string) + - event: ProvidedUnPayablePoint(bytes32,uint256,uint256,uint256,string,bytes32) handler: handleProvidedUnPayablePoint - - event: SavedPurchase(string,uint256,uint256,string,string,uint32,address,bytes32) + - event: SavedPurchase(string,uint256,uint256,string,bytes32,uint32,address,bytes32) handler: handleSavedPurchase - event: Withdrawn(address,uint256,uint256,uint256) handler: handleWithdrawn @@ -68,22 +68,31 @@ dataSources: language: wasm/assemblyscript entities: - AddedShop + - ClosedWithdrawal - IncreasedProvidedPoint - IncreasedSettledPoint - IncreasedUsedPoint + - OpenedWithdrawal + - RemovedShop - UpdatedShop abis: - name: ShopCollection file: $DMS_OSX_MODULE/artifacts/contracts/ShopCollection.sol/ShopCollection.json eventHandlers: - - event: AddedShop(string,uint256,uint256,bytes32) + - event: AddedShop(bytes32,string,uint256,uint256,address) handler: handleAddedShop - - event: IncreasedProvidedPoint(string,uint256,uint256,string) + - event: ClosedWithdrawal(bytes32,uint256,address) + handler: handleClosedWithdrawal + - event: IncreasedProvidedPoint(bytes32,uint256,uint256,string) handler: handleIncreasedProvidedPoint - - event: IncreasedSettledPoint(string,uint256,uint256,string) + - event: IncreasedSettledPoint(bytes32,uint256,uint256,string) handler: handleIncreasedSettledPoint - - event: IncreasedUsedPoint(string,uint256,uint256,string) + - event: IncreasedUsedPoint(bytes32,uint256,uint256,string) handler: handleIncreasedUsedPoint - - event: UpdatedShop(string,uint256,uint256,bytes32) + - event: OpenedWithdrawal(bytes32,uint256,address) + handler: handleOpenedWithdrawal + - event: RemovedShop(bytes32) + handler: handleRemovedShop + - event: UpdatedShop(bytes32,string,uint256,uint256,address) handler: handleUpdatedShop file: ./src/shop-collection.ts diff --git a/packages/subgraph/schema.graphql b/packages/subgraph/schema.graphql index 78a0805a..c170232b 100644 --- a/packages/subgraph/schema.graphql +++ b/packages/subgraph/schema.graphql @@ -35,10 +35,12 @@ type PaidPoint @entity(immutable: true) { account: Bytes! # address paidAmountPoint: BigInt! # uint256 value: BigInt! # uint256 + fee: BigInt! # uint256 + feeValue: BigInt! # uint256 balancePoint: BigInt! # uint256 purchaseId: String! # string purchaseAmount: BigInt! # uint256 - shopId: String! # string + shopId: Bytes! # bytes32 blockNumber: BigInt! blockTimestamp: BigInt! transactionHash: Bytes! @@ -49,10 +51,12 @@ type PaidToken @entity(immutable: true) { account: Bytes! # address paidAmountToken: BigInt! # uint256 value: BigInt! # uint256 + fee: BigInt! # uint256 + feeValue: BigInt! # uint256 balanceToken: BigInt! # uint256 purchaseId: String! # string purchaseAmount: BigInt! # uint256 - shopId: String! # string + shopId: Bytes! # bytes32 blockNumber: BigInt! blockTimestamp: BigInt! transactionHash: Bytes! @@ -65,7 +69,7 @@ type ProvidedPoint @entity(immutable: true) { value: BigInt! # uint256 balancePoint: BigInt! # uint256 purchaseId: String! # string - shopId: String! # string + shopId: Bytes! # bytes32 blockNumber: BigInt! blockTimestamp: BigInt! transactionHash: Bytes! @@ -78,7 +82,7 @@ type ProvidedToken @entity(immutable: true) { value: BigInt! # uint256 balanceToken: BigInt! # uint256 purchaseId: String! # string - shopId: String! # string + shopId: Bytes! # bytes32 blockNumber: BigInt! blockTimestamp: BigInt! transactionHash: Bytes! @@ -87,7 +91,7 @@ type ProvidedToken @entity(immutable: true) { type ProvidedTokenForSettlement @entity(immutable: true) { id: Bytes! account: Bytes! # address - shopId: String! # string + shopId: Bytes! # bytes32 providedAmountPoint: BigInt! # uint256 providedAmountToken: BigInt! # uint256 value: BigInt! # uint256 @@ -105,7 +109,7 @@ type ProvidedUnPayablePoint @entity(immutable: true) { value: BigInt! # uint256 balancePoint: BigInt! # uint256 purchaseId: String! # string - shopId: String! # string + shopId: Bytes! # bytes32 blockNumber: BigInt! blockTimestamp: BigInt! transactionHash: Bytes! @@ -117,7 +121,7 @@ type SavedPurchase @entity(immutable: true) { timestamp: BigInt! # uint256 amount: BigInt! # uint256 currency: String! # string - shopId: String! # string + shopId: Bytes! # bytes32 method: BigInt! # uint32 account: Bytes! # address phone: Bytes! # bytes32 @@ -166,7 +170,7 @@ type UserTradeHistory @entity(immutable: true) { balancePoint: BigInt! balanceToken: BigInt! purchaseId: String - shopId : String + shopId: Bytes! # bytes32 blockNumber: BigInt! blockTimestamp: BigInt! transactionHash: Bytes! @@ -180,7 +184,7 @@ type UserUnPayableTradeHistory @entity(immutable: true) { amount: BigInt! balance: BigInt! purchaseId: String - shopId : String + shopId: Bytes! # bytes32 blockNumber: BigInt! blockTimestamp: BigInt! transactionHash: Bytes! @@ -205,7 +209,7 @@ enum ShopAction { type ShopTradeHistory @entity(immutable: true) { id: Bytes! - shopId: String! # string + shopId: Bytes! # bytes32 purchaseId: String action: ShopAction! @@ -221,12 +225,20 @@ type ShopTradeHistory @entity(immutable: true) { transactionHash: Bytes! } +enum ShopDataAction { + Create, + Update, + Remove +} + type Shop @entity { id: ID! # shopId + name: String! # string provideWaitTime: BigInt! # uint256 providePercent: BigInt! # uint256 - phone: Bytes! # bytes32 + account: Bytes! # address + action: ShopDataAction! providedPoint: BigInt! usedPoint: BigInt! diff --git a/packages/subgraph/src/ledger.ts b/packages/subgraph/src/ledger.ts index 7ece5330..2a028316 100644 --- a/packages/subgraph/src/ledger.ts +++ b/packages/subgraph/src/ledger.ts @@ -28,7 +28,7 @@ import { UserUnPayableTradeHistory, } from "../generated/schema"; import { BigInt, Bytes } from "@graphprotocol/graph-ts"; -import { AmountUnit, NullAccount } from "./utils"; +import { AmountUnit, NullAccount, NullBytes32 } from "./utils"; export function handleChangedPointType(event: ChangedPointTypeEvent): void { let entity = new ChangedPointType(event.transaction.hash.concatI32(event.logIndex.toI32())); @@ -81,6 +81,8 @@ export function handlePaidPoint(event: PaidPointEvent): void { entity.account = event.params.account; entity.paidAmountPoint = event.params.paidAmountPoint.div(AmountUnit); entity.value = event.params.value.div(AmountUnit); + entity.fee = event.params.fee.div(AmountUnit); + entity.feeValue = event.params.feeValue.div(AmountUnit); entity.balancePoint = event.params.balancePoint.div(AmountUnit); entity.purchaseId = event.params.purchaseId; entity.purchaseAmount = event.params.purchaseAmount.div(AmountUnit); @@ -100,6 +102,8 @@ export function handlePaidToken(event: PaidTokenEvent): void { entity.account = event.params.account; entity.paidAmountToken = event.params.paidAmountToken.div(AmountUnit); entity.value = event.params.value.div(AmountUnit); + entity.fee = event.params.fee.div(AmountUnit); + entity.feeValue = event.params.feeValue.div(AmountUnit); entity.balanceToken = event.params.balanceToken.div(AmountUnit); entity.purchaseId = event.params.purchaseId; entity.purchaseAmount = event.params.purchaseAmount.div(AmountUnit); @@ -317,7 +321,7 @@ export function handleDepositedForHistory(event: DepositedEvent): void { entity.balanceToken = event.params.balanceToken.div(AmountUnit); entity.balancePoint = balanceEntity.point; entity.purchaseId = ""; - entity.shopId = ""; + entity.shopId = NullBytes32; entity.blockNumber = event.block.number; entity.blockTimestamp = event.block.timestamp; @@ -343,7 +347,7 @@ export function handleWithdrawnForHistory(event: WithdrawnEvent): void { entity.balanceToken = event.params.balanceToken.div(AmountUnit); entity.balancePoint = balanceEntity.point; entity.purchaseId = ""; - entity.shopId = ""; + entity.shopId = NullBytes32; entity.blockNumber = event.block.number; entity.blockTimestamp = event.block.timestamp; @@ -401,7 +405,7 @@ export function handleChangedPointForUnPayablePointHistory(event: ChangedToPayab entity.amount = event.params.changedAmountPoint.div(AmountUnit); entity.balance = BigInt.fromI32(0); entity.purchaseId = ""; - entity.shopId = ""; + entity.shopId = NullBytes32; entity.blockNumber = event.block.number; entity.blockTimestamp = event.block.timestamp; @@ -427,7 +431,7 @@ export function handleChangedPointForHistory(event: ChangedToPayablePointEvent): entity.balancePoint = event.params.balancePoint.div(AmountUnit); entity.balanceToken = balanceEntity.token; entity.purchaseId = ""; - entity.shopId = ""; + entity.shopId = NullBytes32; entity.blockNumber = event.block.number; entity.blockTimestamp = event.block.timestamp; diff --git a/packages/subgraph/src/shop-collection.ts b/packages/subgraph/src/shop-collection.ts index dd6badd8..7a923ddb 100644 --- a/packages/subgraph/src/shop-collection.ts +++ b/packages/subgraph/src/shop-collection.ts @@ -3,6 +3,7 @@ import { IncreasedSettledPoint as IncreasedSettledPointEvent, IncreasedProvidedPoint as IncreasedProvidedPointEvent, IncreasedUsedPoint as IncreasedUsedPointEvent, + RemovedShop as RemovedShopEvent, UpdatedShop as UpdatedShopEvent, } from "../generated/ShopCollection/ShopCollection"; import { Shop, ShopTradeHistory } from "../generated/schema"; @@ -10,11 +11,13 @@ import { BigInt } from "@graphprotocol/graph-ts"; import { AmountUnit } from "./utils"; export function handleAddedShop(event: AddedShopEvent): void { - let entity = new Shop(event.params.shopId); + let entity = new Shop(event.params.shopId.toString()); + entity.name = event.params.name; entity.provideWaitTime = event.params.provideWaitTime; entity.providePercent = event.params.providePercent; - entity.phone = event.params.phone; + entity.account = event.params.account; + entity.action = "Create"; entity.providedPoint = BigInt.fromI32(0); entity.usedPoint = BigInt.fromI32(0); @@ -27,12 +30,25 @@ export function handleAddedShop(event: AddedShopEvent): void { entity.save(); } +export function handleRemovedShop(event: RemovedShopEvent): void { + let shopEntity = Shop.load(event.params.shopId.toString()); + if (shopEntity !== null) { + shopEntity.action = "Remove"; + + shopEntity.blockNumber = event.block.number; + shopEntity.blockTimestamp = event.block.timestamp; + shopEntity.transactionHash = event.transaction.hash; + shopEntity.save(); + } +} + export function handleUpdatedShop(event: UpdatedShopEvent): void { - let shopEntity = Shop.load(event.params.shopId); + let shopEntity = Shop.load(event.params.shopId.toString()); if (shopEntity !== null) { - shopEntity.phone = event.params.phone; + shopEntity.name = event.params.name; shopEntity.provideWaitTime = event.params.provideWaitTime; shopEntity.providePercent = event.params.providePercent; + shopEntity.action = "Update"; shopEntity.blockNumber = event.block.number; shopEntity.blockTimestamp = event.block.timestamp; @@ -49,7 +65,7 @@ export function handleIncreasedSettledPoint(event: IncreasedSettledPointEvent): entity.increase = event.params.increase.div(AmountUnit); entity.settledPoint = event.params.total.div(AmountUnit); - let shopEntity = Shop.load(event.params.shopId); + let shopEntity = Shop.load(event.params.shopId.toString()); if (shopEntity !== null) { entity.providedPoint = shopEntity.providedPoint; entity.usedPoint = shopEntity.usedPoint; @@ -78,7 +94,7 @@ export function handleIncreasedProvidedPoint(event: IncreasedProvidedPointEvent) entity.increase = event.params.increase.div(AmountUnit); entity.providedPoint = event.params.total.div(AmountUnit); - let shopEntity = Shop.load(event.params.shopId); + let shopEntity = Shop.load(event.params.shopId.toString()); if (shopEntity !== null) { entity.usedPoint = shopEntity.usedPoint; entity.settledPoint = shopEntity.settledPoint; @@ -107,7 +123,7 @@ export function handleIncreasedUsedPoint(event: IncreasedUsedPointEvent): void { entity.increase = event.params.increase.div(AmountUnit); entity.usedPoint = event.params.total.div(AmountUnit); - let shopEntity = Shop.load(event.params.shopId); + let shopEntity = Shop.load(event.params.shopId.toString()); if (shopEntity !== null) { entity.providedPoint = shopEntity.providedPoint; entity.settledPoint = shopEntity.settledPoint; diff --git a/packages/subgraph/src/utils.ts b/packages/subgraph/src/utils.ts index c0cccd97..44a9c7bd 100644 --- a/packages/subgraph/src/utils.ts +++ b/packages/subgraph/src/utils.ts @@ -2,3 +2,6 @@ import { BigInt, Bytes } from "@graphprotocol/graph-ts"; export const AmountUnit = BigInt.fromI32(1_000_000_000); export const NullAccount: Bytes = Bytes.fromHexString("0x0000000000000000000000000000000000000000"); +export const NullBytes32: Bytes = Bytes.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000000" +); From d49e670ba56b1d410ee7de178a49df87fc678a6d Mon Sep 17 00:00:00 2001 From: Michael Kim Date: Fri, 6 Oct 2023 11:23:51 +0900 Subject: [PATCH 3/3] Upgrade package version --- packages/contracts-lib/package.json | 2 +- packages/contracts/package.json | 2 +- packages/faker/package.json | 2 +- packages/relay/package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/contracts-lib/package.json b/packages/contracts-lib/package.json index 4968b746..bd13a2bb 100644 --- a/packages/contracts-lib/package.json +++ b/packages/contracts-lib/package.json @@ -1,6 +1,6 @@ { "name": "dms-osx-lib", - "version": "1.1.0", + "version": "1.1.1", "description": "", "main": "dist/bundle-cjs.js", "module": "dist/bundle-esm.js", diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 6e7b28d1..fb30a88d 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -1,6 +1,6 @@ { "name": "dms-osx-artifacts", - "version": "1.1.0", + "version": "1.1.1", "description": "Smart contracts that decentralized point systems", "files": [ "**/*.sol" diff --git a/packages/faker/package.json b/packages/faker/package.json index 298bc98b..fba5e174 100644 --- a/packages/faker/package.json +++ b/packages/faker/package.json @@ -47,7 +47,7 @@ "assert": "^2.0.0", "axios": "^0.26.0", "chai": "^4.3.7", - "dms-osx-artifacts": "^1.1.0", + "dms-osx-artifacts": "^1.1.1", "dotenv": "^10.0.0", "ethereum-waffle": "^4.0.10", "ethers": "^5.7.0", diff --git a/packages/relay/package.json b/packages/relay/package.json index f0d2ae39..df015831 100644 --- a/packages/relay/package.json +++ b/packages/relay/package.json @@ -56,7 +56,7 @@ "chai": "^4.3.7", "chai-http": "^4.3.7", "cors": "^2.8.5", - "dms-osx-artifacts": "^1.1.0", + "dms-osx-artifacts": "^1.1.1", "dotenv": "^10.0.0", "ethereum-waffle": "^4.0.10", "ethers": "^5.7.0",