Skip to content

Commit

Permalink
still store matured vaults (#482)
Browse files Browse the repository at this point in the history
* still store matured vaults

* add changeset
  • Loading branch information
franzns authored Jun 18, 2024
1 parent fd0f501 commit 34a7d70
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-fans-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'backend': minor
---

update sftmx vaults when they are matured
6 changes: 0 additions & 6 deletions modules/actions/sftmx/sync-staking-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,8 @@ export async function syncStakingData(stakingContractAddress: Address, viemClien
ftmStakingId: stakingContractAddress,
},
update: {
id: vaultData.id,
vaultIndex: parseFloat(vaultData.vaultIndex.toString()),
ftmStaked: formatEther(vaultData.ftmStaked),
unlockTimestamp: parseFloat(vaultData.unlockTimestamp.toString()),
validatorAddress: vaultData.validatorAddress,
validatorId: vaultData.validatorId.toString(),
matured: vaultData.matured,
ftmStakingId: stakingContractAddress,
},
});
}
Expand Down
36 changes: 33 additions & 3 deletions modules/sources/contracts/fetch-sftmx-staking-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export async function fetchSftmxStakingData(
functionName: 'getMaturedVaultLength',
});

const maturedVaults: Address[] = [];
const maturedVaults: { address: Address; index: bigint }[] = [];

for (let i = 0n; i < maturedVaultCount; i++) {
const maturedVaultAddress = await client.readContract({
Expand All @@ -145,7 +145,7 @@ export async function fetchSftmxStakingData(
functionName: 'getMaturedVault',
args: [i],
});
maturedVaults.push(maturedVaultAddress);
maturedVaults.push({ address: maturedVaultAddress, index: i });
}

for (let i = 1n; i <= stakingData.numberOfVaults; i++) {
Expand Down Expand Up @@ -177,12 +177,42 @@ export async function fetchSftmxStakingData(
id: vaultAddress,
ftmStaked: lockedStake,
ftmStakingId: stakingContractAddress,
matured: maturedVaults.includes(vaultAddress),
matured: false,
unlockTimestamp: endTime,
validatorAddress: validatorAddress,
validatorId: validatorId,
vaultIndex: vaultIndex,
});
}
for (const maturedVault of maturedVaults) {
const vaultAddress = maturedVault.address;
const validatorId = await client.readContract({
abi: SftmxVault,
address: vaultAddress,
functionName: 'toValidatorID',
});
const validatorAddress = await client.readContract({
abi: SftmxVault,
address: vaultAddress,
functionName: 'toValidator',
});

const [lockedStake, fromEpoch, endTime, duration] = await client.readContract({
abi: SFC,
address: SFC_ADDRESS,
functionName: 'getLockupInfo',
args: [vaultAddress, validatorId],
});
stakingData.vaults.push({
id: vaultAddress,
ftmStaked: lockedStake,
ftmStakingId: stakingContractAddress,
matured: true,
unlockTimestamp: endTime,
validatorAddress: validatorAddress,
validatorId: validatorId,
vaultIndex: maturedVault.index,
});
}
return stakingData;
}

0 comments on commit 34a7d70

Please sign in to comment.