From aa53cfb09e7a6009743b1584a52df5a65f58b7bc Mon Sep 17 00:00:00 2001 From: Danial Date: Tue, 6 Aug 2024 17:01:39 +0900 Subject: [PATCH] Change an event of the contract Ledger --- .../contracts/contracts/ledger/Ledger.sol | 14 +- packages/contracts/package.json | 4 +- packages/library/package.json | 2 +- packages/relay/package.json | 4 +- .../manifest/subgraph.placeholder.yaml | 4 +- packages/subgraph-sidechain/schema.graphql | 13 -- packages/subgraph-sidechain/src/ledger.ts | 121 +++--------------- yarn.lock | 8 +- 8 files changed, 40 insertions(+), 130 deletions(-) diff --git a/packages/contracts/contracts/ledger/Ledger.sol b/packages/contracts/contracts/ledger/Ledger.sol index dd742065..4f922653 100644 --- a/packages/contracts/contracts/ledger/Ledger.sol +++ b/packages/contracts/contracts/ledger/Ledger.sol @@ -30,7 +30,8 @@ contract Ledger is LedgerStorage, Initializable, OwnableUpgradeable, UUPSUpgrade string purchaseId, bytes32 shopId, address provider, - uint256 consumedToken + uint256 consumedToken, + uint256 providerBalanceToken ); /// @notice 포인트가 지급될 때 발생되는 이벤트 @@ -43,7 +44,8 @@ contract Ledger is LedgerStorage, Initializable, OwnableUpgradeable, UUPSUpgrade string purchaseId, bytes32 shopId, address provider, - uint256 consumedToken + uint256 consumedToken, + uint256 providerBalanceToken ); event Refunded( @@ -244,6 +246,7 @@ contract Ledger is LedgerStorage, Initializable, OwnableUpgradeable, UUPSUpgrade tokenBalances[_sender] -= consumedToken; } uint256 balance = unPayablePointBalances[_phone]; + uint256 providerTokenBalance = tokenBalances[_sender]; emit ProvidedUnPayablePoint( _phone, _loyaltyPoint, @@ -253,7 +256,8 @@ contract Ledger is LedgerStorage, Initializable, OwnableUpgradeable, UUPSUpgrade _purchaseId, _shopId, _sender, - consumedToken + consumedToken, + providerTokenBalance ); } @@ -297,6 +301,7 @@ contract Ledger is LedgerStorage, Initializable, OwnableUpgradeable, UUPSUpgrade tokenBalances[systemAccount] += consumedToken; } uint256 balance = pointBalances[_account]; + uint256 providerTokenBalance = tokenBalances[_sender]; emit ProvidedPoint( _account, _loyaltyPoint, @@ -306,7 +311,8 @@ contract Ledger is LedgerStorage, Initializable, OwnableUpgradeable, UUPSUpgrade _purchaseId, _shopId, _sender, - consumedToken + consumedToken, + providerTokenBalance ); } diff --git a/packages/contracts/package.json b/packages/contracts/package.json index aa6d5e63..029b5ec6 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -1,6 +1,6 @@ { "name": "acc-contracts-v2", - "version": "2.5.3", + "version": "2.6.0", "description": "Smart contracts that decentralized loyalty systems", "files": [ "**/*.sol" @@ -70,7 +70,7 @@ "@openzeppelin/contracts": "^4.9.5", "@openzeppelin/contracts-upgradeable": "^4.9.5", "@openzeppelin/hardhat-upgrades": "^1.28.0", - "acc-bridge-contracts-v2": "~2.3.1", + "acc-bridge-contracts-v2": "~2.5.0", "loyalty-tokens": "~2.1.1", "multisig-wallet-contracts": "~2.0.0" } diff --git a/packages/library/package.json b/packages/library/package.json index 8cf1893d..bfbf2d7d 100644 --- a/packages/library/package.json +++ b/packages/library/package.json @@ -1,6 +1,6 @@ { "name": "acc-contracts-lib-v2", - "version": "2.5.3", + "version": "2.6.0", "description": "", "main": "dist/bundle-cjs.js", "module": "dist/bundle-esm.js", diff --git a/packages/relay/package.json b/packages/relay/package.json index 0e091cdd..7c7db8cb 100644 --- a/packages/relay/package.json +++ b/packages/relay/package.json @@ -66,8 +66,8 @@ "@types/urijs": "^1.19.12" }, "dependencies": { - "acc-bridge-contracts-v2": "~2.3.1", - "acc-contracts-v2": "~2.5.3", + "acc-bridge-contracts-v2": "~2.5.0", + "acc-contracts-v2": "~2.6.0", "argparse": "^2.0.1", "assert": "^2.0.0", "axios": "^1.6.7", diff --git a/packages/subgraph-sidechain/manifest/subgraph.placeholder.yaml b/packages/subgraph-sidechain/manifest/subgraph.placeholder.yaml index 92aa3fc9..64237e86 100644 --- a/packages/subgraph-sidechain/manifest/subgraph.placeholder.yaml +++ b/packages/subgraph-sidechain/manifest/subgraph.placeholder.yaml @@ -54,9 +54,9 @@ dataSources: eventHandlers: - event: Deposited(address,uint256,uint256,uint256) handler: handleDeposited - - event: ProvidedPoint(address,uint256,uint256,string,uint256,string,bytes32,address,uint256) + - event: ProvidedPoint(address,uint256,uint256,string,uint256,string,bytes32,address,uint256,uint256) handler: handleProvidedPoint - - event: ProvidedUnPayablePoint(bytes32,uint256,uint256,string,uint256,string,bytes32,address,uint256) + - event: ProvidedUnPayablePoint(bytes32,uint256,uint256,string,uint256,string,bytes32,address,uint256,uint256) handler: handleProvidedUnPayablePoint - event: Withdrawn(address,uint256,uint256,uint256) handler: handleWithdrawn diff --git a/packages/subgraph-sidechain/schema.graphql b/packages/subgraph-sidechain/schema.graphql index 74b8d1a2..d54fe16a 100644 --- a/packages/subgraph-sidechain/schema.graphql +++ b/packages/subgraph-sidechain/schema.graphql @@ -220,16 +220,3 @@ type ChainBridgeWithdrawn @entity(immutable: true) { blockTimestamp: BigInt! transactionHash: Bytes! } - -type LoyaltyProvide @entity(immutable: true) { - id: Bytes! - provider: Bytes! # address - receiver: Bytes! # address - amountPoint: BigInt! # uint256 - amountToken: BigInt! # uint256 - balancePoint: BigInt! # uint256 - balanceToken: BigInt! # uint256 - blockNumber: BigInt! - blockTimestamp: BigInt! - transactionHash: Bytes! -} diff --git a/packages/subgraph-sidechain/src/ledger.ts b/packages/subgraph-sidechain/src/ledger.ts index 91f60dcd..cfe1a5f2 100644 --- a/packages/subgraph-sidechain/src/ledger.ts +++ b/packages/subgraph-sidechain/src/ledger.ts @@ -7,11 +7,7 @@ import { ProvidedUnPayablePoint as ProvidedUnPayablePointEvent, Withdrawn as WithdrawnEvent, } from "../generated/Ledger/Ledger"; -import { - ProvidedLoyaltyPointToPhone as ProvidedLoyaltyPointToPhoneEvent, - ProvidedLoyaltyPointToAddress as ProvidedLoyaltyPointToAddressEvent, - SavedPurchase as SavedPurchaseEvent, -} from "../generated/LoyaltyProvider/LoyaltyProvider"; +import { SavedPurchase as SavedPurchaseEvent } from "../generated/LoyaltyProvider/LoyaltyProvider"; import { LoyaltyPaymentEvent as LoyaltyPaymentEventEvent } from "../generated/LoyaltyConsumer/LoyaltyConsumer"; import { ChangedToPayablePoint as ChangedToPayablePointEvent, @@ -34,7 +30,6 @@ import { LoyaltyPaymentEvent, LoyaltyBridgeDeposited, LoyaltyBridgeWithdrawn, - LoyaltyProvide, BurnedPoint, BurnedUnPayablePoint, } from "../generated/schema"; @@ -335,6 +330,13 @@ export function handleProvidedForUnPayablePointForHistory(event: ProvidedUnPayab entity.save(); if (event.params.consumedToken.gt(BigInt.fromI32(0))) { + const balanceEntity2 = handleChangedBalanceToken( + event.params.provider, + event.params.providerBalanceToken, + event.block.number, + event.block.timestamp, + event.transaction.hash + ); let entity2 = new UserTradeHistory( event.transaction.hash.concatI32(event.logIndex.plus(BigInt.fromI32(64)).toI32()) ); @@ -344,8 +346,8 @@ export function handleProvidedForUnPayablePointForHistory(event: ProvidedUnPayab entity2.amountPoint = BigInt.fromI32(0); entity2.amountToken = event.params.consumedToken.div(AmountUnit); entity2.amountValue = event.params.providedValue.div(AmountUnit); - entity2.feePoint = BigInt.fromI32(0); - entity2.feeToken = BigInt.fromI32(0); + entity2.feePoint = balanceEntity2.point; + entity2.feeToken = event.params.providerBalanceToken.div(AmountUnit); entity2.feeValue = BigInt.fromI32(0); entity2.currency = event.params.currency; entity2.balancePoint = BigInt.fromI32(0); @@ -394,6 +396,13 @@ export function handleProvidedPointForHistory(event: ProvidedPointEvent): void { entity.save(); if (event.params.consumedToken.gt(BigInt.fromI32(0))) { + const balanceEntity2 = handleChangedBalanceToken( + event.params.provider, + event.params.providerBalanceToken, + event.block.number, + event.block.timestamp, + event.transaction.hash + ); let entity2 = new UserTradeHistory( event.transaction.hash.concatI32(event.logIndex.plus(BigInt.fromI32(64)).toI32()) ); @@ -407,8 +416,8 @@ export function handleProvidedPointForHistory(event: ProvidedPointEvent): void { entity2.feeToken = BigInt.fromI32(0); entity2.feeValue = BigInt.fromI32(0); entity2.currency = event.params.currency; - entity2.balancePoint = BigInt.fromI32(0); - entity2.balanceToken = BigInt.fromI32(0); + entity2.balancePoint = balanceEntity2.point; + entity2.balanceToken = event.params.providerBalanceToken.div(AmountUnit); entity2.purchaseId = ""; entity2.paymentId = event.params.account; entity2.shopId = NullBytes32; @@ -807,95 +816,3 @@ export function handleBridgeWithdrawnForHistory(event: BridgeWithdrawnEvent): vo } // endregion - -export function handleProvidedLoyaltyPointToAddress(event: ProvidedLoyaltyPointToAddressEvent): void { - let entity1 = new LoyaltyProvide(event.transaction.hash.concatI32(event.logIndex.toI32())); - entity1.provider = event.params.provider; - entity1.receiver = event.params.receiver; - entity1.amountPoint = event.params.amountPoint.div(AmountUnit); - entity1.amountToken = event.params.amountToken.div(AmountUnit); - - entity1.blockNumber = event.block.number; - entity1.blockTimestamp = event.block.timestamp; - entity1.transactionHash = event.transaction.hash; - entity1.save(); - - const balanceEntity = handleChangedBalanceToken( - event.params.provider, - event.params.balanceToken, - event.block.number, - event.block.timestamp, - event.transaction.hash - ); - - let entity = new UserTradeHistory( - event.transaction.hash.concatI32(event.logIndex.plus(BigInt.fromI32(128)).toI32()) - ); - entity.account = event.params.provider; - entity.action = UserAction.TRANSFER_OUT; - entity.cancel = false; - entity.amountPoint = BigInt.fromI32(0); - entity.amountToken = event.params.amountToken.div(AmountUnit); - entity.amountValue = event.params.amountPoint.div(AmountUnit); - entity.feePoint = BigInt.fromI32(0); - entity.feeToken = BigInt.fromI32(0); - entity.feeValue = BigInt.fromI32(0); - entity.currency = "TOKEN"; - entity.balanceToken = balanceEntity.token; - entity.balancePoint = balanceEntity.point; - entity.purchaseId = ""; - entity.paymentId = event.params.receiver; - entity.shopId = NullBytes32; - entity.provider = event.params.provider; - - entity.blockNumber = event.block.number; - entity.blockTimestamp = event.block.timestamp; - entity.transactionHash = event.transaction.hash; - entity.save(); -} - -export function handleProvidedLoyaltyPointToPhone(event: ProvidedLoyaltyPointToPhoneEvent): void { - let entity1 = new LoyaltyProvide(event.transaction.hash.concatI32(event.logIndex.toI32())); - entity1.provider = event.params.provider; - entity1.receiver = event.params.receiver; - entity1.amountPoint = event.params.amountPoint.div(AmountUnit); - entity1.amountToken = event.params.amountToken.div(AmountUnit); - - entity1.blockNumber = event.block.number; - entity1.blockTimestamp = event.block.timestamp; - entity1.transactionHash = event.transaction.hash; - entity1.save(); - - const balanceEntity = handleChangedBalanceToken( - event.params.provider, - event.params.balanceToken, - event.block.number, - event.block.timestamp, - event.transaction.hash - ); - - let entity = new UserTradeHistory( - event.transaction.hash.concatI32(event.logIndex.plus(BigInt.fromI32(128)).toI32()) - ); - entity.account = event.params.provider; - entity.action = UserAction.TRANSFER_OUT; - entity.cancel = false; - entity.amountPoint = BigInt.fromI32(0); - entity.amountToken = event.params.amountToken.div(AmountUnit); - entity.amountValue = event.params.amountPoint.div(AmountUnit); - entity.feePoint = BigInt.fromI32(0); - entity.feeToken = BigInt.fromI32(0); - entity.feeValue = BigInt.fromI32(0); - entity.currency = "TOKEN"; - entity.balanceToken = balanceEntity.token; - entity.balancePoint = balanceEntity.point; - entity.purchaseId = ""; - entity.paymentId = event.params.receiver; - entity.shopId = NullBytes32; - entity.provider = event.params.provider; - - entity.blockNumber = event.block.number; - entity.blockTimestamp = event.block.timestamp; - entity.transactionHash = event.transaction.hash; - entity.save(); -} diff --git a/yarn.lock b/yarn.lock index ac55c93a..a8532aef 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1900,10 +1900,10 @@ abstract-leveldown@~6.2.1: level-supports "~1.0.0" xtend "~4.0.0" -acc-bridge-contracts-v2@~2.3.1: - version "2.3.1" - resolved "https://registry.yarnpkg.com/acc-bridge-contracts-v2/-/acc-bridge-contracts-v2-2.3.1.tgz#0e6e5bd4297b024f3ed82b8e7dbcea34cd4f81dd" - integrity sha512-3wYqCOuW/LJZLjjNblA8iyig3+9pK4G3IHH++/Zm5wDjHv1crvtLOM1x+QepKrsXMA4MWONZz/DrwIol+80e0Q== +acc-bridge-contracts-v2@~2.5.0: + version "2.5.0" + resolved "https://registry.yarnpkg.com/acc-bridge-contracts-v2/-/acc-bridge-contracts-v2-2.5.0.tgz#f5e9e1eb60650f6938e00e121894971ac846367e" + integrity sha512-qE3jxuinP+i4QKzDddbCACuBxnMUbyVFy24PGyUzscIR5bqkLYsZRaRb7Ozq1lnJHZSr226e6axvIDQDRpgkxg== dependencies: "@openzeppelin/contracts" "^4.9.5" "@openzeppelin/contracts-upgradeable" "^4.9.5"