Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change an event of the contract Ledger #31

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions packages/contracts/contracts/ledger/Ledger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ contract Ledger is LedgerStorage, Initializable, OwnableUpgradeable, UUPSUpgrade
string purchaseId,
bytes32 shopId,
address provider,
uint256 consumedToken
uint256 consumedToken,
uint256 providerBalanceToken
);

/// @notice 포인트가 지급될 때 발생되는 이벤트
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -253,7 +256,8 @@ contract Ledger is LedgerStorage, Initializable, OwnableUpgradeable, UUPSUpgrade
_purchaseId,
_shopId,
_sender,
consumedToken
consumedToken,
providerTokenBalance
);
}

Expand Down Expand Up @@ -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,
Expand All @@ -306,7 +311,8 @@ contract Ledger is LedgerStorage, Initializable, OwnableUpgradeable, UUPSUpgrade
_purchaseId,
_shopId,
_sender,
consumedToken
consumedToken,
providerTokenBalance
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/library/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/relay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions packages/subgraph-sidechain/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
}
121 changes: 19 additions & 102 deletions packages/subgraph-sidechain/src/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -34,7 +30,6 @@ import {
LoyaltyPaymentEvent,
LoyaltyBridgeDeposited,
LoyaltyBridgeWithdrawn,
LoyaltyProvide,
BurnedPoint,
BurnedUnPayablePoint,
} from "../generated/schema";
Expand Down Expand Up @@ -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())
);
Expand All @@ -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);
Expand Down Expand Up @@ -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())
);
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading