Skip to content

Commit

Permalink
Improve versions (#143)
Browse files Browse the repository at this point in the history
* [improve-versions] change version logic

* [improve-versions] change to v1
  • Loading branch information
Cast0001 authored Jul 30, 2024
1 parent b5c6dd5 commit 8359d08
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
14 changes: 7 additions & 7 deletions src/methods/osToken/requests/getOsTokenConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ const getOsTokenData = async (input: GetOsTokenConfigInput) => {

const vaultContract = contracts.helpers.createVault(vaultAddress)
const version = await vaultContract.version()
const isSecondVersion = version === 2n
const isV1Version = version === 1n

if (isSecondVersion) {
const [ _, thresholdPercent, ltvPercent ] = await contracts.base.mintTokenConfig.v2.getConfig(vaultAddress)
if (isV1Version) {
const [ thresholdPercent, ltvPercent ] = await Promise.all([
contracts.base.mintTokenConfig.v1.liqThresholdPercent(),
contracts.base.mintTokenConfig.v1.ltvPercent(),
])

return {
ltvPercent,
thresholdPercent,
}
}
else {
const [ thresholdPercent, ltvPercent ] = await Promise.all([
contracts.base.mintTokenConfig.v1.liqThresholdPercent(),
contracts.base.mintTokenConfig.v1.ltvPercent(),
])
const [ _, thresholdPercent, ltvPercent ] = await contracts.base.mintTokenConfig.v2.getConfig(vaultAddress)

return {
ltvPercent,
Expand Down
4 changes: 2 additions & 2 deletions src/methods/vault/transactions/operate/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export const commonLogic = async (values: MulticallInput) => {

// Temporal logic while different types of vaults exist
const version = Number(await vaultContract.version())
const isSecondVersion = version === 2
const isV1Version = version === 1

if (isSecondVersion) {
if (!isV1Version) {
if (validatorsRoot) {
throw new Error('To set validatorsRoot in version 2 of vault, use the vault.setDepositDataRoot() method')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const checkDepositDataManagerAccess = async ({ userAddress, vaultAddress, contra
const vaultContract = await contracts.helpers.createVault(vaultAddress)
const version = await vaultContract.version()

const depositDataManager = version > 1n
? await contracts.base.depositDataRegistry.getDepositDataManager(vaultAddress)
: await vaultContract.keysManager()
const depositDataManager = version === 1n
? await vaultContract.keysManager()
: await contracts.base.depositDataRegistry.getDepositDataManager(vaultAddress)

const hasAccess = depositDataManager.toLowerCase() === userAddress.toLowerCase()

Expand Down
4 changes: 2 additions & 2 deletions src/methods/vault/transactions/withdraw/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const commonLogic = async (values: WithdrawInput) => {

// In the second version of the vault we do not use the redeem method,
// the funds are always withdrawn via a queue
const isSecondVersion = version === 2
const isV1Version = version === 1

const baseMulticallArgs: Omit<Parameters<typeof vaultMulticall>[0], 'request'> = {
keeperContract: contracts.base.keeper,
Expand All @@ -29,7 +29,7 @@ export const commonLogic = async (values: WithdrawInput) => {

const isCollateralized = await contracts.base.keeper.isCollateralized(vaultAddress)

if (isCollateralized || isSecondVersion) {
if (isCollateralized || !isV1Version) {
const result = await vaultMulticall<[ { shares: bigint } ]>({
...baseMulticallArgs,
request: {
Expand Down
10 changes: 5 additions & 5 deletions src/utils/getValidLtvPercent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ const getValidLtvPercent = async (values: Input) => {
const vaultContract = contracts.helpers.createVault(vaultAddress)

const version = await vaultContract.version()
const isSecondVersion = version === 2n
const isV1Version = version === 1n

// in second version 100% ltv percent = 1 ether in wei
const percent = isSecondVersion
? ltvPercent / 100000000000000n
: ltvPercent
// in second+ version 100% ltv percent = 1 ether in wei
const percent = isV1Version
? ltvPercent
: ltvPercent / 100000000000000n

return percent
}
Expand Down

0 comments on commit 8359d08

Please sign in to comment.