Skip to content

Commit 352337f

Browse files
fix: onchain sync vault bug (#228)
* fix: onchain sync vault bug * fix: use owner again on withdraw * chore: typos --------- Co-authored-by: Filippo Fontana <filippo@embrio.tech>
1 parent 9e0500e commit 352337f

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/handlers/merkleProofManagerHandlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { multiMapper } from "../helpers/multiMapper";
22
import { logEvent, serviceError } from "../helpers/logger";
33
import { BlockchainService, MerkleProofManagerService, PolicyService } from "../services";
4-
import { Abis, getVersionForContract, REGISTRY_VERSION_ORDER } from "../contracts";
4+
import { Abis, REGISTRY_VERSION_ORDER } from "../contracts";
55

66
multiMapper("merkleProofManagerFactory:DeployMerkleProofManager", async ({ event, context }) => {
77
logEvent(event, context, "merkleProofManagerFactory:DeployMerkleProofManager");

src/handlers/vaultHandlers.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,14 @@ multiMapper("vault:DepositClaimable", async ({ event, context }) => {
244244
const { decimals: shareDecimals } = token.read();
245245
if (typeof shareDecimals !== "number") return serviceError("Share decimals is required");
246246

247-
const invstorAccount = (await AccountService.getOrInit(
247+
const investorAccount = (await AccountService.getOrInit(
248248
context,
249249
{
250250
address: controller,
251251
},
252252
event
253253
)) as AccountService;
254-
const { address: investorAddress } = invstorAccount.read();
254+
const { address: investorAddress } = investorAccount.read();
255255

256256
const _it = await InvestorTransactionService.depositClaimable(
257257
context,
@@ -300,7 +300,6 @@ multiMapper("vault:RedeemClaimable", async ({ event, context }) => {
300300
if (!vault) return serviceError(`Vault not found. Cannot retrieve vault configuration`);
301301
const { poolId, tokenId, assetAddress } = vault.read();
302302

303-
304303
const asset = (await AssetService.get(context, {
305304
address: assetAddress,
306305
centrifugeId,
@@ -314,14 +313,14 @@ multiMapper("vault:RedeemClaimable", async ({ event, context }) => {
314313
const { decimals: shareDecimals } = token.read();
315314
if (typeof shareDecimals !== "number") return serviceError("Share decimals is required");
316315

317-
const invstorAccount = (await AccountService.getOrInit(
316+
const investorAccount = (await AccountService.getOrInit(
318317
context,
319318
{
320319
address: controller,
321320
},
322321
event
323322
)) as AccountService;
324-
const { address: investorAddress } = invstorAccount.read();
323+
const { address: investorAddress } = investorAccount.read();
325324

326325
const _it = await InvestorTransactionService.redeemClaimable(
327326
context,
@@ -357,7 +356,7 @@ multiMapper("vault:RedeemClaimable", async ({ event, context }) => {
357356

358357
multiMapper("vault:Deposit", async ({ event, context }) => {
359358
logEvent(event, context, "vault:Deposit");
360-
const { owner, assets, shares } = event.args;
359+
const { sender, owner, assets, shares } = event.args;
361360
const vaultId = event.log.address;
362361
if (!vaultId) return serviceError(`Vault id not found in event. Cannot identify vault`);
363362

@@ -383,15 +382,31 @@ multiMapper("vault:Deposit", async ({ event, context }) => {
383382
if (typeof assetDecimals !== "number")
384383
return serviceError("Asset decimals is required to compute share price");
385384

386-
const invstorAccount = (await AccountService.getOrInit(
385+
// NOTE: In our current implementation v3.1 there is a bug in the SyncDepositVault where `sender` and `receiver` are swapped
386+
// in the event data.
387+
// -> Use sender as our investor in this case.
388+
let investor: `0x${string}`;
389+
switch (kind) {
390+
case "Async":
391+
investor = owner;
392+
break;
393+
case "SyncDepositAsyncRedeem":
394+
case "Sync":
395+
investor = sender;
396+
break;
397+
default:
398+
return serviceError("Unknown vault kind");
399+
}
400+
401+
const investorAccount = (await AccountService.getOrInit(
387402
context,
388403
{
389-
address: owner,
404+
address: investor,
390405
},
391406
event
392407
)) as AccountService;
393408

394-
const { address: investorAddress } = invstorAccount.read();
409+
const { address: investorAddress } = investorAccount.read();
395410

396411
const itData = {
397412
poolId,
@@ -509,14 +524,14 @@ multiMapper("vault:Withdraw", async ({ event, context }) => {
509524
if (!token) return serviceError(`Token not found. Cannot retrieve token configuration`);
510525
const { decimals: shareDecimals } = token.read();
511526
if (typeof shareDecimals !== "number") return serviceError("Share decimals is required");
512-
const invstorAccount = (await AccountService.getOrInit(
527+
const investorAccount = (await AccountService.getOrInit(
513528
context,
514529
{
515530
address: owner,
516531
},
517532
event
518533
)) as AccountService;
519-
const { address: investorAddress } = invstorAccount.read();
534+
const { address: investorAddress } = investorAccount.read();
520535

521536
const itData = {
522537
poolId,
@@ -530,7 +545,6 @@ multiMapper("vault:Withdraw", async ({ event, context }) => {
530545
currencyAssetId: assetId,
531546
};
532547

533-
534548
switch (kind) {
535549
case "Sync":
536550
return serviceError("Sync vaults are not supported yet");

0 commit comments

Comments
 (0)