diff --git a/subgraphs/magicswap/schema.graphql b/subgraphs/magicswap/schema.graphql index 15458b1..692b1cf 100644 --- a/subgraphs/magicswap/schema.graphql +++ b/subgraphs/magicswap/schema.graphql @@ -106,7 +106,7 @@ type VaultReserveItem @entity { vault: Token! collection: Collection! tokenId: BigInt! - amount: Int! + amount: BigInt! } type Pair @entity { @@ -214,7 +214,7 @@ type TransactionItem @entity(immutable: true) { vault: Token! collection: Collection! tokenId: BigInt! - amount: Int! + amount: BigInt! } type Incentive @entity { diff --git a/subgraphs/magicswap/src/helpers.ts b/subgraphs/magicswap/src/helpers.ts index 4dc2aee..e630f9a 100644 --- a/subgraphs/magicswap/src/helpers.ts +++ b/subgraphs/magicswap/src/helpers.ts @@ -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; diff --git a/subgraphs/magicswap/src/mappings/vault.ts b/subgraphs/magicswap/src/mappings/vault.ts index 6d8acaf..c70d563 100644 --- a/subgraphs/magicswap/src/mappings/vault.ts +++ b/subgraphs/magicswap/src/mappings/vault.ts @@ -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); @@ -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(); } @@ -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()); @@ -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(); }