Skip to content

Commit

Permalink
👷‍♂️ MimSwap update: Integrate MIM/USDB to farm logic (#512)
Browse files Browse the repository at this point in the history
* integrate MIM_USDB to farm logic

* update conditions
  • Loading branch information
0xhardrefresh authored Dec 4, 2024
1 parent 9298b58 commit b93b2a5
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 22 deletions.
11 changes: 10 additions & 1 deletion src/components/pools/pool/PoolActionBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="pool-header">
<h2 class="title">{{ titleText }}</h2>

<TokenPair class="token-pair" chainIcon :pool="pool" :iconSize="50" />
<TokenPair class="token-pair" chainIcon :pool="pool" :iconSize="50" :isFarm="isFarm" />

<div class="initial-parameters">
<ParameterChip>{{ feeTier }}</ParameterChip>
Expand Down Expand Up @@ -137,6 +137,10 @@ export default {
return this.isFarm ? "Farm" : "Pool";
},
isDeprecatedFarm() {
return this.isFarm && this.pool.settings.isDeprecatedFarm;
},
isRemove() {
return this.activeTab === "remove";
},
Expand Down Expand Up @@ -167,6 +171,11 @@ export default {
if (value) {
this.activeTab = stakeTabItems[0];
this.tabItems = [...stakeTabItems];
if(this.isDeprecatedFarm) {
this.activeTab = stakeTabItems[1];
this.tabItems = [stakeTabItems[1]];
}
}
},
immediate: true,
Expand Down
19 changes: 19 additions & 0 deletions src/components/pools/pool/TokenPair.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<img src="@/assets/images/pools/rewards/pills-icon.svg" />
<span>1x Multiplier </span>
</div>
<div class="deprecated-wrap" v-if="isDeprecatedFarm">
<span>Deprecated</span>
</div>
</div>
</div>
</template>
Expand All @@ -43,6 +46,7 @@ const borderRadiusCoefficient = 2.5;
export default {
props: {
isFarm: { type: Boolean, default: false },
pool: { type: Object },
chainIcon: Boolean,
iconSize: { type: Number, default: 46 },
Expand All @@ -51,6 +55,10 @@ export default {
},
computed: {
isDeprecatedFarm() {
return this.isFarm && this.pool.settings.isDeprecatedFarm;
},
baseIconSize() {
return this.iconSize - this.borderThickness * 2;
},
Expand Down Expand Up @@ -105,6 +113,17 @@ export default {
align-items: center;
}
.deprecated-wrap {
padding: 2px 12px;
border-radius: 12px;
background: linear-gradient(90deg, #8c4040 0%, #6b2424 100%);
font-size: 12px;
font-style: normal;
font-weight: 400;
line-height: normal;
margin-top: 3px;
}
.token-icon {
margin-right: 0 !important;
}
Expand Down
8 changes: 6 additions & 2 deletions src/components/pools/pool/actions/Unstake.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
/>
</div>

<StakingAprWrap :pool="pool" v-if="!rewardPointsType" />
<RewardPointsBannerWrap :rewardPointsType="rewardPointsType" v-else />
<StakingAprWrap :pool="pool" v-if="!rewardPointsType && !isDeprecatedFarm" />
<RewardPointsBannerWrap :rewardPointsType="rewardPointsType" v-else-if="rewardPointsType" />

<BaseButton primary @click="actionHandler" :disabled="isButtonDisabled">
{{ buttonText }}
Expand Down Expand Up @@ -59,6 +59,10 @@ export default {
account: "getAccount",
}),
isDeprecatedFarm(){
return this.pool.settings.isDeprecatedFarm;
},
isBlastLockLogic() {
return !!this.pool.lockInfo;
},
Expand Down
11 changes: 6 additions & 5 deletions src/components/pools/pool/position/Staked.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
<RewardsWrap :pool="pool" v-if="earnedBalance || rewardPointsType" />

<BaseButton
v-if="
hasStakeLogic &&
(isUserPositionOpen || earnedBalance) &&
!rewardPointsType
"
v-if="showButton"
primary
@click="actionHandler"
:disabled="isButtonDisabled"
Expand Down Expand Up @@ -63,6 +59,11 @@ export default {
account: "getAccount",
chainId: "getChainId",
}),
showButton() {
return this.hasStakeLogic &&
(this.isUserPositionOpen || this.earnedBalance) &&
!this.rewardPointsType && !this.pool.settings.isDeprecatedFarm
},
hasLockLogic() {
return !!this.pool.lockInfo;
},
Expand Down
12 changes: 9 additions & 3 deletions src/components/pools/table/poolFarms/PoolFarmCardItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
>
<div class="label">{{ poolLabel }}</div>

<TokenPair :pool="pool" chainIcon />
<TokenPair :pool="pool" chainIcon :isFarm="isFarm" />

<div class="indicator">
<h3 class="title">TVL</h3>
Expand All @@ -22,7 +22,7 @@
v-if="rewardPointsType"
/>

<div class="token-icons" v-else>
<div class="token-icons" v-else-if="rewardTokens?.length">
<BaseTokenIcon
v-for="(token, index) in rewardTokens"
:icon="token.icon"
Expand All @@ -31,14 +31,16 @@
:key="index"
/>
</div>
<p v-else>-</p>
</div>

<div class="indicator">
<div v-if="!rewardPointsType">
<h3 class="title">APR</h3>
<div class="value apr">
<div class="value apr" v-if="poolApr">
{{ poolApr }}
</div>
<p v-else>-</p>
</div>

<div v-else>
Expand Down Expand Up @@ -66,6 +68,10 @@ export default {
type: Object,
required: true,
},
isFarm: {
type: Boolean,
default: false,
},
},
computed: {
Expand Down
15 changes: 9 additions & 6 deletions src/components/pools/table/poolFarms/PoolFarmsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
v-for="(pool, index) in poolsToRender"
:key="index"
:pool="pool"
:isFarm="true"
/>
</div>

Expand All @@ -42,6 +43,7 @@
v-for="(pool, index) in poolsToRender"
:key="index"
:pool="pool"
:isFarm="true"
/>
</div>

Expand Down Expand Up @@ -132,15 +134,15 @@ export default {
},
showDeprecatedButton() {
const hasDeprecatedPool = this.poolsToRender.some(
(pool: MagicLPInfo) => pool.settings.isDeprecated
const hasDeprecatedPool = this.pools.some(
(pool: MagicLPInfo) => pool.settings.isDeprecatedFarm
);
return this.poolsToRender.length && hasDeprecatedPool;
},
deprecatedButtonText() {
if (this.showActivePools) return " Show Deprecated pools";
return "Hide Deprecated pools";
if (this.showActivePools) return "Show Deprecated Farms";
return "Hide Deprecated Farms";
},
},
Expand Down Expand Up @@ -191,15 +193,16 @@ export default {
filterByActivepools(pools: MagicLPInfo[]) {
if (this.showActivePools) {
return pools.filter((pool) => {
return !pool.settings.isDeprecated;
return !pool.settings.isDeprecatedFarm;
});
}
return pools.sort((a, b) => {
const settingsA = a?.settings;
const settingsB = b?.settings;
if (settingsA || settingsB) {
return +settingsA?.isDeprecated - +settingsB?.isDeprecated;
// @ts-ignore
return +settingsA?.isDeprecatedFarm - +settingsB?.isDeprecatedFarm;
}
return 1;
Expand Down
12 changes: 9 additions & 3 deletions src/components/pools/table/poolFarms/PoolFarmsTableItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
>
<div class="label">{{ poolLabel }}</div>
<div class="column">
<TokenPair :pool="pool" chainIcon />
<TokenPair :pool="pool" chainIcon :isFarm="isFarm" />
</div>

<div class="column">${{ tvl }}</div>
Expand All @@ -18,7 +18,7 @@
name
v-if="rewardPointsType"
/>
<div class="token-icons" v-else>
<div class="token-icons" v-else-if="rewardTokens?.length">
<BaseTokenIcon
v-for="(token, index) in rewardTokens"
:icon="token.icon"
Expand All @@ -27,6 +27,7 @@
:key="index"
/>
</div>
<p v-else>-</p>
</div>

<div class="column apr">
Expand All @@ -35,7 +36,8 @@
multiplier
v-if="rewardPointsType"
/>
<span class="apr-value" v-else>{{ poolApr }}</span>
<span class="apr-value" v-else-if="poolApr">{{ poolApr }}</span>
<p v-else>-</p>
</div>
</router-link>
</template>
Expand All @@ -53,6 +55,10 @@ export default {
type: Object as PropType<MagicLPInfo>,
required: true,
},
isFarm: {
type: Boolean,
default: false,
},
},
computed: {
Expand Down
2 changes: 2 additions & 0 deletions src/configs/pools/blastPools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const blastPools: Array<PoolConfig | AdditionalPoolConfig> = [
isDeprecated: false,
isMim: true,
isPointsLogic: true,
isLockAsStake: true,
isDeprecatedFarm: true,
},
initialParameters: {
I: 1000000000000000000n,
Expand Down
4 changes: 4 additions & 0 deletions src/configs/pools/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export type AdditionalPoolConfig = {
isDeprecated: boolean;
isMim: boolean;
rewardPointsType?: RewardPointsTypes;
isLockAsStake?: boolean;
isDeprecatedFarm?: boolean;
};
stakeContract?: ContractInfo;
};
Expand All @@ -38,6 +40,8 @@ type PoolSettings = {
isMim: boolean;
isPointsLogic?: boolean;
rewardPointsType?: RewardPointsTypes;
isLockAsStake?: boolean;
isDeprecatedFarm?: boolean;
};

type InitialParameters = {
Expand Down
15 changes: 14 additions & 1 deletion src/helpers/pools/getPoolInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ export const getPoolInfo = async (
swapRouter: getSwapRouterByChain(Number(poolChainId)),
};

if (account && poolConfig.lockContract)
if (account && poolConfig.lockContract) {
poolInfo.lockInfo = await getLockInfo(account, poolChainId, poolConfig);
poolInfo.stakeInfo = parseLockAsStake(poolInfo.lockInfo);
poolInfo.stakeContract = poolConfig.lockContract;
}


if (poolConfig.stakeContract)
poolInfo.poolAPR = await getPoolApr(poolChainId, poolInfo, tokensPrices);
Expand Down Expand Up @@ -204,6 +208,15 @@ export const getStakeInfo = async (
};
};

export const parseLockAsStake = (lockInfo: any) => {
return {
balance: lockInfo.balances.unlocked,
allowance: lockInfo.allowance,
earned: 0,
earnedInfo: [],
};
}

export const getUserLocks = async (
account: Address,
chainId: number,
Expand Down
19 changes: 19 additions & 0 deletions src/helpers/pools/swap/magicLp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,25 @@ export const getLpInfo = async (
});
}

//
if (lp.lockContract?.address) {
const lockedSupply = await publicClient.readContract({
address: lp.lockContract.address,
abi: lp.lockContract.abi as any,
functionName: "lockedSupply",
args: [],
});

const unlockedSupply = await publicClient.readContract({
address: lp.lockContract.address,
abi: lp.lockContract.abi as any,
functionName: "unlockedSupply",
args: [],
});

stakedTotalSupply = lockedSupply + unlockedSupply;
}

const userInfo = await getUserLpInfo(
lp.contract.address,
getSwapRouterByChain(chainId),
Expand Down
2 changes: 1 addition & 1 deletion src/views/pool/PoolFarms.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default {
}),
poolFarmsConfigs() {
return this.poolConfigs.filter(({ stakeContract }) => stakeContract);
return this.poolConfigs.filter(({ stakeContract, lockContract }) => stakeContract || lockContract);
},
},
Expand Down

0 comments on commit b93b2a5

Please sign in to comment.