Skip to content

Commit

Permalink
use bigint for nft amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
alecananian committed Dec 19, 2024
1 parent c1e4da9 commit 36d649e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions subgraphs/magicswap/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ type VaultReserveItem @entity {
vault: Token!
collection: Collection!
tokenId: BigInt!
amount: Int!
amount: BigInt!
}

type Pair @entity {
Expand Down Expand Up @@ -214,7 +214,7 @@ type TransactionItem @entity(immutable: true) {
vault: Token!
collection: Collection!
tokenId: BigInt!
amount: Int!
amount: BigInt!
}

type Incentive @entity {
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/magicswap/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export const getOrCreateVaultReserveItem = (
reserveItem.vault = vault;
reserveItem.collection = collection;
reserveItem.tokenId = tokenId;
reserveItem.amount = 0;
reserveItem.amount = ZERO_BI;
}

return reserveItem;
Expand Down
10 changes: 5 additions & 5 deletions subgraphs/magicswap/src/mappings/vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function handleDeposit(event: Deposit): void {
params.collection,
params.tokenId
);
reserveItem.amount += params.amount.toI32();
reserveItem.amount = reserveItem.amount.plus(params.amount);
reserveItem.save();

const transaction = getOrCreateTransaction(event);
Expand All @@ -77,7 +77,7 @@ export function handleDeposit(event: Deposit): void {
transactionItem.vault = vault;
transactionItem.collection = params.collection;
transactionItem.tokenId = params.tokenId;
transactionItem.amount = params.amount.toI32();
transactionItem.amount = transactionItem.amount.plus(params.amount);
transactionItem.save();
}

Expand All @@ -90,8 +90,8 @@ export function handleWithdraw(event: Withdraw): void {
params.collection,
params.tokenId
);
reserveItem.amount -= params.amount.toI32();
if (reserveItem.amount > 0) {
reserveItem.amount = reserveItem.amount.minus(params.amount);
if (reserveItem.amount.gt(ZERO_BI)) {
reserveItem.save();
} else {
store.remove("VaultReserveItem", reserveItem.id.toHexString());
Expand All @@ -111,6 +111,6 @@ export function handleWithdraw(event: Withdraw): void {
transactionItem.vault = vault;
transactionItem.collection = params.collection;
transactionItem.tokenId = params.tokenId;
transactionItem.amount = params.amount.toI32();
transactionItem.amount = params.amount;
transactionItem.save();
}

0 comments on commit 36d649e

Please sign in to comment.