mirror of
https://github.com/Instadapp/assembly.git
synced 2024-07-29 22:37:06 +00:00
yearn
This commit is contained in:
parent
2ae25c1f7b
commit
0926447767
400
abis/read/yearnV2.json
Normal file
400
abis/read/yearnV2.json
Normal file
|
|
@ -0,0 +1,400 @@
|
|||
[
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "contract YearnV2Interface",
|
||||
"name": "vault",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "getAvailableDepositLimit",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "contract YearnV2Interface",
|
||||
"name": "vault",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "getBalance",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "contract YearnV2Interface",
|
||||
"name": "vault",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "getExpectedShareValue",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "address[]",
|
||||
"name": "wantAddresses",
|
||||
"type": "address[]"
|
||||
}
|
||||
],
|
||||
"name": "getPositions",
|
||||
"outputs": [
|
||||
{
|
||||
"components": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "vaultLatestVersion",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "vault",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "want",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "pricePerShare",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "availableDepositLimit",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "totalAssets",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "balanceOf",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "wantBalanceOf",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "expectedShareValue",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "decimals",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "isDeprecated",
|
||||
"type": "bool"
|
||||
},
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "emergencyShutdown",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"internalType": "struct Helpers.VaultData[]",
|
||||
"name": "",
|
||||
"type": "tuple[]"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "address[]",
|
||||
"name": "wantAddresses",
|
||||
"type": "address[]"
|
||||
}
|
||||
],
|
||||
"name": "getPositionsForLatest",
|
||||
"outputs": [
|
||||
{
|
||||
"components": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "vaultLatestVersion",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "vault",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "want",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "pricePerShare",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "availableDepositLimit",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "totalAssets",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "balanceOf",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "wantBalanceOf",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "expectedShareValue",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "decimals",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "isDeprecated",
|
||||
"type": "bool"
|
||||
},
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "emergencyShutdown",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"internalType": "struct Helpers.VaultData[]",
|
||||
"name": "",
|
||||
"type": "tuple[]"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "contract YearnV2Interface",
|
||||
"name": "vault",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "getPricePerShare",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "getRegistry",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "contract YearnRegistryInterface",
|
||||
"name": "",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"stateMutability": "pure",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "contract YearnV2Interface",
|
||||
"name": "vault",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "getTotalAssets",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "contract YearnV2Interface",
|
||||
"name": "vault",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "isEmergencyShutdown",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "want",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "isWantSupported",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "want",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "latestForWant",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "want",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "listVaultsForWant",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "address[]",
|
||||
"name": "vaultAddresses",
|
||||
"type": "address[]"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "name",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "string",
|
||||
"name": "",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "want",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "numVaultsForWant",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "numVaults",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
}
|
||||
]
|
||||
100
components/protocols/yearn-v2/CardYearn.vue
Normal file
100
components/protocols/yearn-v2/CardYearn.vue
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
<template>
|
||||
<div
|
||||
class="flex-shrink-0 bg-white rounded-lg relative flex flex-col flex-1 px-4 pt-4 pb-6 dark:bg-dark-500"
|
||||
style="box-shadow: -1px -3px 10px rgba(12, 25, 91, 0.03), 2px 4px 12px rgba(12, 25, 91, 0.05)"
|
||||
>
|
||||
<div class="flex items-center h-14">
|
||||
<div class="flex mr-4 -space-x-3 overflow-hidden">
|
||||
<IconCurrency :currency="tokenKey" class="w-12 h-12" no-height />
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col flex-grow">
|
||||
<div class="mb-1 font-medium leading-none whitespace-no-wrap text-19">
|
||||
{{ formatUsd(supplyUsd) }}
|
||||
</div>
|
||||
<div class="flex leading-none whitespace-no-wrap">
|
||||
<span class="text-grey-pure text-14"
|
||||
>{{ formatDecimal(supply) }} {{ symbol }}</span
|
||||
>
|
||||
<Info
|
||||
:text="`${formatUsd(priceInUsd, 2)}/${symbol}`"
|
||||
icon="price"
|
||||
class="ml-1"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid w-full grid-cols-3 gap-4 mt-4">
|
||||
{{ formatPercent(netAPY) }} net APY
|
||||
</div>
|
||||
|
||||
<hr class="mt-4" />
|
||||
|
||||
<div class="flex items-center justify-around mt-6">
|
||||
<button
|
||||
class="mr-4 h-10 w-full bg-primary-blue-dark shadow text-white rounded-[4px] hover:bg-primary-blue-hover"
|
||||
@click="showSupply"
|
||||
>
|
||||
Supply
|
||||
</button>
|
||||
<button
|
||||
class="h-10 w-full text-primary-blue-dark shadow border border-primary-blue-dark hover:border-primary-blue-hover rounded-[4px] hover:text-primary-blue-hover"
|
||||
@click="showWithdraw"
|
||||
>
|
||||
Withdraw
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { computed, defineComponent, useContext } from "@nuxtjs/composition-api";
|
||||
import { useFormatting } from "~/composables/useFormatting";
|
||||
import { useToken } from "~/composables/useToken";
|
||||
|
||||
export default defineComponent({
|
||||
props: {
|
||||
tokenKey: { type: String, required: true },
|
||||
vault: { type: String, default: null },
|
||||
supply: { type: String, required: true },
|
||||
supplyUsd: { type: String, required: true },
|
||||
priceInUsd: { type: String, default: "0" },
|
||||
netAPY: { type: String, default: "0" }
|
||||
},
|
||||
|
||||
setup(props) {
|
||||
const { app } = useContext();
|
||||
const { formatPercent, formatUsd, formatDecimal } = useFormatting();
|
||||
const { getTokenByKey } = useToken();
|
||||
|
||||
const symbol = computed(
|
||||
() => getTokenByKey(props.tokenKey)?.symbol || props.tokenKey
|
||||
);
|
||||
|
||||
function showSupply() {
|
||||
app.router.push({ hash: `supply?vault=${props.vault}` });
|
||||
}
|
||||
|
||||
function showWithdraw() {
|
||||
app.router.push({ hash: `withdraw?vault=${props.vault}` });
|
||||
}
|
||||
|
||||
return {
|
||||
showSupply,
|
||||
showWithdraw,
|
||||
formatPercent,
|
||||
formatUsd,
|
||||
formatDecimal,
|
||||
symbol
|
||||
};
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<style scoped>
|
||||
.position-button {
|
||||
@apply flex-1;
|
||||
@apply h-8;
|
||||
@apply h-8;
|
||||
}
|
||||
</style>
|
||||
183
components/sidebar/context/yearn-v2/SidebarYearnV2Supply.vue
Normal file
183
components/sidebar/context/yearn-v2/SidebarYearnV2Supply.vue
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
<template>
|
||||
<SidebarContextRootContainer>
|
||||
<template #title>Supply {{ symbol }}</template>
|
||||
|
||||
<SidebarSectionValueWithIcon label="Token Balance" center>
|
||||
<template #icon
|
||||
><IconCurrency :currency="token.key" class="w-20 h-20" noHeight
|
||||
/></template>
|
||||
<template #value>{{ formatNumber(balance) }} {{ symbol }}</template>
|
||||
</SidebarSectionValueWithIcon>
|
||||
|
||||
<div class="bg-[#C5CCE1] bg-opacity-[0.15] mt-10 p-8">
|
||||
<h3 class="text-primary-gray text-xs font-semibold mb-2.5">
|
||||
Amount to supply
|
||||
</h3>
|
||||
|
||||
<input-numeric
|
||||
v-model="amount"
|
||||
placeholder="Amount to supply"
|
||||
:error="errors.amount.message"
|
||||
>
|
||||
<template v-if="!isMaxAmount" #suffix>
|
||||
<div class="absolute mt-2 top-0 right-0 mr-4">
|
||||
<button
|
||||
type="button"
|
||||
class="text-primary-blue-dark font-semibold text-sm hover:text-primary-blue-hover"
|
||||
@click="toggle"
|
||||
>
|
||||
Max
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
</input-numeric>
|
||||
|
||||
<div class="flex flex-shrink-0 mt-10">
|
||||
<ButtonCTA
|
||||
class="w-full"
|
||||
:disabled="!isValid || pending"
|
||||
:loading="pending"
|
||||
@click="cast"
|
||||
>
|
||||
Supply
|
||||
</ButtonCTA>
|
||||
</div>
|
||||
|
||||
<ValidationErrors :error-messages="errorMessages" class="mt-6" />
|
||||
</div>
|
||||
</SidebarContextRootContainer>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { computed, defineComponent, ref } from "@nuxtjs/composition-api";
|
||||
import InputNumeric from "~/components/common/input/InputNumeric.vue";
|
||||
import { useBalances } from "~/composables/useBalances";
|
||||
import { useNotification } from "~/composables/useNotification";
|
||||
import { useBigNumber } from "~/composables/useBigNumber";
|
||||
import { useFormatting } from "~/composables/useFormatting";
|
||||
import { useValidators } from "~/composables/useValidators";
|
||||
import { useValidation } from "~/composables/useValidation";
|
||||
import { useToken } from "~/composables/useToken";
|
||||
import { useParsing } from "~/composables/useParsing";
|
||||
import { useMaxAmountActive } from "~/composables/useMaxAmountActive";
|
||||
import { useWeb3 } from "@instadapp/vue-web3";
|
||||
import ToggleButton from "~/components/common/input/ToggleButton.vue";
|
||||
import { useDSA } from "~/composables/useDSA";
|
||||
import ButtonCTA from "~/components/common/input/ButtonCTA.vue";
|
||||
import Button from "~/components/Button.vue";
|
||||
import { useSidebar } from "~/composables/useSidebar";
|
||||
import DSA from "dsa-connect";
|
||||
import { useYearnV2Position } from "~/composables/protocols/useYearnV2Position";
|
||||
export default defineComponent({
|
||||
components: { InputNumeric, ToggleButton, ButtonCTA, Button },
|
||||
props: {
|
||||
vault: { type: String, required: true }
|
||||
},
|
||||
setup(props) {
|
||||
const { close } = useSidebar();
|
||||
const { account } = useWeb3();
|
||||
const { dsa } = useDSA();
|
||||
const { getTokenByKey, valInt } = useToken();
|
||||
const { getBalanceByKey, fetchBalances } = useBalances();
|
||||
const { formatNumber, formatUsdMax, formatUsd } = useFormatting();
|
||||
const { isZero, gt, plus } = useBigNumber();
|
||||
const { parseSafeFloat } = useParsing();
|
||||
const {
|
||||
showPendingTransaction,
|
||||
showWarning,
|
||||
showConfirmedTransaction
|
||||
} = useNotification();
|
||||
|
||||
const { vaults, refreshPosition } = useYearnV2Position();
|
||||
const selectedVault = computed(() =>
|
||||
vaults.value.find(v => v.address === props.vault)
|
||||
);
|
||||
|
||||
const amount = ref("");
|
||||
const amountParsed = computed(() => parseSafeFloat(amount.value));
|
||||
|
||||
const token = computed(() =>
|
||||
selectedVault.value
|
||||
? getTokenByKey(selectedVault.value.token.display_name.toLowerCase())
|
||||
: null
|
||||
);
|
||||
const symbol = computed(() => token.value?.symbol);
|
||||
const decimals = computed(() => token.value?.decimals);
|
||||
const balance = computed(() => getBalanceByKey(token.value?.key));
|
||||
|
||||
const { toggle, isMaxAmount } = useMaxAmountActive(amount, balance);
|
||||
|
||||
const { validateAmount, validateIsLoggedIn } = useValidators();
|
||||
const errors = computed(() => {
|
||||
const hasAmountValue = !isZero(amount.value);
|
||||
|
||||
return {
|
||||
amount: {
|
||||
message: validateAmount(amountParsed.value, balance.value),
|
||||
show: hasAmountValue
|
||||
},
|
||||
auth: { message: validateIsLoggedIn(!!account.value), show: true }
|
||||
};
|
||||
});
|
||||
const { errorMessages, isValid } = useValidation(errors);
|
||||
|
||||
const pending = ref(false);
|
||||
|
||||
async function cast() {
|
||||
pending.value = true;
|
||||
|
||||
const amount = isMaxAmount.value
|
||||
? dsa.value.maxValue
|
||||
: valInt(amountParsed.value, decimals.value);
|
||||
|
||||
const spells = dsa.value.Spell();
|
||||
|
||||
spells.add({
|
||||
//@ts-ignore
|
||||
connector: "YEARN-VAULT-A",
|
||||
method: "deposit",
|
||||
args: [props.vault, amount, 0, 0]
|
||||
});
|
||||
|
||||
try {
|
||||
const txHash = await (dsa.value as DSA).cast({
|
||||
spells,
|
||||
from: account.value,
|
||||
onReceipt: async receipt => {
|
||||
showConfirmedTransaction(receipt.transactionHash);
|
||||
|
||||
await fetchBalances(true);
|
||||
await refreshPosition();
|
||||
}
|
||||
});
|
||||
|
||||
showPendingTransaction(txHash);
|
||||
} catch (error) {
|
||||
showWarning(error.message);
|
||||
}
|
||||
|
||||
pending.value = false;
|
||||
|
||||
close();
|
||||
}
|
||||
|
||||
return {
|
||||
selectedVault,
|
||||
pending,
|
||||
cast,
|
||||
errors,
|
||||
amount,
|
||||
token,
|
||||
symbol,
|
||||
balance,
|
||||
formatNumber,
|
||||
formatUsdMax,
|
||||
formatUsd,
|
||||
toggle,
|
||||
isMaxAmount,
|
||||
errorMessages,
|
||||
isValid
|
||||
};
|
||||
}
|
||||
});
|
||||
</script>
|
||||
179
components/sidebar/context/yearn-v2/SidebarYearnV2Withdraw.vue
Normal file
179
components/sidebar/context/yearn-v2/SidebarYearnV2Withdraw.vue
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
<template>
|
||||
<SidebarContextRootContainer>
|
||||
<template #title>Withdraw {{ symbol }}</template>
|
||||
|
||||
<SidebarSectionValueWithIcon label="Token Balance" center>
|
||||
<template #icon
|
||||
><IconCurrency :currency="token.key" class="w-20 h-20" noHeight
|
||||
/></template>
|
||||
<template #value>{{ formatNumber(balance) }} {{ symbol }}</template>
|
||||
</SidebarSectionValueWithIcon>
|
||||
|
||||
<div class="bg-[#C5CCE1] bg-opacity-[0.15] mt-10 p-8">
|
||||
<h3 class="text-primary-gray text-xs font-semibold mb-2.5">
|
||||
Amount to withdraw
|
||||
</h3>
|
||||
|
||||
<input-numeric
|
||||
v-model="amount"
|
||||
placeholder="Amount to withdraw"
|
||||
:error="errors.amount.message"
|
||||
>
|
||||
<template v-if="!isMaxAmount" #suffix>
|
||||
<div class="absolute mt-2 top-0 right-0 mr-4">
|
||||
<button
|
||||
type="button"
|
||||
class="text-primary-blue-dark font-semibold text-sm hover:text-primary-blue-hover"
|
||||
@click="toggle"
|
||||
>
|
||||
Max
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
</input-numeric>
|
||||
|
||||
<div class="flex flex-shrink-0 mt-10">
|
||||
<ButtonCTA
|
||||
class="w-full"
|
||||
:disabled="!isValid || pending"
|
||||
:loading="pending"
|
||||
@click="cast"
|
||||
>
|
||||
Withdraw
|
||||
</ButtonCTA>
|
||||
</div>
|
||||
|
||||
<ValidationErrors :error-messages="errorMessages" class="mt-6" />
|
||||
</div>
|
||||
</SidebarContextRootContainer>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { computed, defineComponent, onMounted, ref } from '@nuxtjs/composition-api'
|
||||
import InputNumeric from '~/components/common/input/InputNumeric.vue'
|
||||
import { useBalances } from '~/composables/useBalances'
|
||||
import { useBigNumber } from '~/composables/useBigNumber'
|
||||
import { useFormatting } from '~/composables/useFormatting'
|
||||
import { useValidators } from '~/composables/useValidators'
|
||||
import { useValidation } from '~/composables/useValidation'
|
||||
import { useToken } from '~/composables/useToken'
|
||||
import { useParsing } from '~/composables/useParsing'
|
||||
import { useMaxAmountActive } from '~/composables/useMaxAmountActive'
|
||||
import { useWeb3 } from '@instadapp/vue-web3'
|
||||
import ToggleButton from '~/components/common/input/ToggleButton.vue'
|
||||
import { useDSA } from '~/composables/useDSA'
|
||||
import ButtonCTA from '~/components/common/input/ButtonCTA.vue'
|
||||
import { useNotification } from '~/composables/useNotification'
|
||||
import Button from '~/components/Button.vue'
|
||||
import { useSidebar } from '~/composables/useSidebar'
|
||||
import { useYearnV2Position } from '~/composables/protocols/useYearnV2Position'
|
||||
|
||||
export default defineComponent({
|
||||
components: { InputNumeric, ToggleButton, ButtonCTA, Button },
|
||||
props: {
|
||||
vault: { type: String, required: true }
|
||||
},
|
||||
setup(props) {
|
||||
const { close } = useSidebar()
|
||||
const { account } = useWeb3()
|
||||
const { dsa } = useDSA()
|
||||
const { getTokenByKey, valInt } = useToken()
|
||||
const { formatNumber, formatUsdMax, formatUsd } = useFormatting()
|
||||
const { isZero, gt, plus, max, minus } = useBigNumber()
|
||||
const { parseSafeFloat } = useParsing()
|
||||
const { showPendingTransaction, showConfirmedTransaction, showWarning } = useNotification()
|
||||
const { fetchBalances } = useBalances();
|
||||
|
||||
const { vaults, refreshPosition } = useYearnV2Position();
|
||||
const selectedVault = computed(() =>
|
||||
vaults.value.find(v => v.address === props.vault)
|
||||
);
|
||||
|
||||
const balance = computed(
|
||||
() => selectedVault.value ? selectedVault.value.position.supply : '0'
|
||||
)
|
||||
|
||||
const amount = ref('')
|
||||
const amountParsed = computed(() => parseSafeFloat(amount.value))
|
||||
|
||||
|
||||
const token = computed(() =>
|
||||
selectedVault.value
|
||||
? getTokenByKey(selectedVault.value.token.display_name.toLowerCase())
|
||||
: null
|
||||
);
|
||||
const symbol = computed(() => token.value?.symbol)
|
||||
const decimals = computed(() => token.value?.decimals)
|
||||
|
||||
|
||||
const { toggle, isMaxAmount } = useMaxAmountActive(amount, balance)
|
||||
|
||||
const { validateAmount, validateIsLoggedIn } = useValidators()
|
||||
|
||||
const errors = computed(() => {
|
||||
const hasAmountValue = !isZero(amount.value)
|
||||
|
||||
return {
|
||||
amount: { message: validateAmount(amountParsed.value, balance.value), show: hasAmountValue },
|
||||
auth: { message: validateIsLoggedIn(!!account.value), show: true },
|
||||
}
|
||||
})
|
||||
const { errorMessages, isValid } = useValidation(errors)
|
||||
|
||||
const pending = ref(false)
|
||||
|
||||
async function cast() {
|
||||
pending.value = true
|
||||
|
||||
const amount = isMaxAmount.value ? dsa.value.maxValue : valInt(amountParsed.value, decimals.value)
|
||||
|
||||
const spells = dsa.value.Spell()
|
||||
|
||||
spells.add({
|
||||
//@ts-ignore
|
||||
connector: "YEARN-VAULT-A",
|
||||
method: 'withdraw',
|
||||
args: [props.vault, amount, 0, 0],
|
||||
})
|
||||
|
||||
try {
|
||||
const txHash = await dsa.value.cast({
|
||||
spells,
|
||||
from: account.value,
|
||||
onReceipt: async receipt => {
|
||||
showConfirmedTransaction(receipt.transactionHash);
|
||||
|
||||
await fetchBalances(true);
|
||||
await refreshPosition();
|
||||
}
|
||||
})
|
||||
|
||||
showPendingTransaction(txHash)
|
||||
} catch (error) {
|
||||
showWarning(error.message)
|
||||
}
|
||||
|
||||
pending.value = false
|
||||
|
||||
close()
|
||||
}
|
||||
|
||||
return {
|
||||
pending,
|
||||
cast,
|
||||
errors,
|
||||
amount,
|
||||
token,
|
||||
symbol,
|
||||
balance,
|
||||
formatNumber,
|
||||
formatUsdMax,
|
||||
formatUsd,
|
||||
toggle,
|
||||
isMaxAmount,
|
||||
errorMessages,
|
||||
isValid
|
||||
}
|
||||
},
|
||||
})
|
||||
</script>
|
||||
131
composables/protocols/useYearnV2Position.ts
Normal file
131
composables/protocols/useYearnV2Position.ts
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
import { useWeb3 } from "@instadapp/vue-web3";
|
||||
import { ref, useContext, watch } from "@nuxtjs/composition-api";
|
||||
import addresses from "~/constant/addresses";
|
||||
import tokens from "~/constant/tokens";
|
||||
import { useDSA } from "../useDSA";
|
||||
import yearnV2ABI from "~/abis/read/yearnV2.json";
|
||||
import useEventBus from "../useEventBus";
|
||||
import BigNumber from "bignumber.js";
|
||||
import { useBigNumber } from "../useBigNumber";
|
||||
|
||||
const resolver = addresses.mainnet.resolver.yearnV2;
|
||||
|
||||
const wantAddresses = [
|
||||
tokens.mainnet.getTokenByKey("weth").address,
|
||||
tokens.mainnet.getTokenByKey("dai").address
|
||||
];
|
||||
|
||||
const vaults = ref([]);
|
||||
|
||||
export function useYearnV2Position() {
|
||||
const { $axios } = useContext();
|
||||
const { times } = useBigNumber();
|
||||
const { library } = useWeb3();
|
||||
const { activeAccount } = useDSA();
|
||||
const { onEvent } = useEventBus();
|
||||
|
||||
const fetchPosition = async () => {
|
||||
vaults.value = [];
|
||||
const availableVaults = await $axios
|
||||
.$get("https://api.yearn.finance/v1/chains/1/vaults/all")
|
||||
.then(vs => vs.filter(v => v.type === "v2"));
|
||||
|
||||
if (!library.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!activeAccount.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
const resolverInstance = new library.value.eth.Contract(
|
||||
yearnV2ABI as any,
|
||||
resolver
|
||||
);
|
||||
|
||||
const tokensArr = wantAddresses; // tokens.mainnet.allTokens.map(a => a.address);
|
||||
|
||||
const rawData = await resolverInstance.methods
|
||||
.getPositionsForLatest(activeAccount.value.address, tokensArr)
|
||||
.call();
|
||||
|
||||
const newVaults = [];
|
||||
|
||||
rawData.forEach(
|
||||
([
|
||||
vaultLatestVersion,
|
||||
vault,
|
||||
want,
|
||||
pricePerShare,
|
||||
availableDepositLimit,
|
||||
totalAssets,
|
||||
balanceOf,
|
||||
wantBalanceOf,
|
||||
expectedShareValue,
|
||||
decimals,
|
||||
isDeprecated,
|
||||
emergencyShutdown
|
||||
]) => {
|
||||
const v = availableVaults.find(v => v.address === vault);
|
||||
if (v) {
|
||||
const supply = new BigNumber(balanceOf)
|
||||
.dividedBy(10 ** decimals)
|
||||
.toFixed();
|
||||
|
||||
newVaults.push({
|
||||
...v,
|
||||
priceInUsd: v.tvl.price.toString(),
|
||||
position: {
|
||||
vaultLatestVersion,
|
||||
vault,
|
||||
want,
|
||||
pricePerShare,
|
||||
availableDepositLimit,
|
||||
totalAssets,
|
||||
balanceOf,
|
||||
wantBalanceOf,
|
||||
expectedShareValue,
|
||||
decimals,
|
||||
isDeprecated,
|
||||
emergencyShutdown,
|
||||
supply,
|
||||
supplyUsd: times(supply, v.tvl.price).toFixed(),
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
vaults.value = newVaults;
|
||||
};
|
||||
|
||||
const refreshPosition = async () => {
|
||||
await fetchPosition();
|
||||
};
|
||||
|
||||
onEvent("protocol::compound::refresh", refreshPosition);
|
||||
|
||||
watch(
|
||||
library,
|
||||
async val => {
|
||||
if (val) {
|
||||
refreshPosition();
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
watch(
|
||||
activeAccount,
|
||||
async val => {
|
||||
if (val) {
|
||||
refreshPosition();
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
return {
|
||||
vaults,
|
||||
refreshPosition
|
||||
};
|
||||
}
|
||||
|
|
@ -41,6 +41,9 @@ import SidebarReflexerWithdraw from '~/components/sidebar/context/reflexer/Sideb
|
|||
import SidebarReflexerBorrow from '~/components/sidebar/context/reflexer/SidebarReflexerBorrow.vue'
|
||||
import SidebarReflexerPayback from '~/components/sidebar/context/reflexer/SidebarReflexerPayback.vue'
|
||||
|
||||
import SidebarYearnV2Supply from "~/components/sidebar/context/yearn-v2/SidebarYearnV2Supply.vue";
|
||||
import SidebarYearnV2Withdraw from '~/components/sidebar/context/yearn-v2/SidebarYearnV2Withdraw.vue'
|
||||
|
||||
import SidebarStrategySelection from '~/components/sidebar/context/strategy/SidebarStrategySelection.vue'
|
||||
import SidebarStrategy from '~/components/sidebar/context/strategy/SidebarStrategy.vue'
|
||||
|
||||
|
|
@ -82,6 +85,11 @@ const sidebars = {
|
|||
"/mainnet/reflexer#withdraw": { component: SidebarReflexerWithdraw },
|
||||
"/mainnet/reflexer#borrow": { component: SidebarReflexerBorrow },
|
||||
"/mainnet/reflexer#payback": { component: SidebarReflexerPayback },
|
||||
|
||||
|
||||
"/mainnet/yearn-v2": { component: null },
|
||||
"/mainnet/yearn-v2#supply": { component: SidebarYearnV2Supply },
|
||||
"/mainnet/yearn-v2#withdraw": { component: SidebarYearnV2Withdraw },
|
||||
};
|
||||
|
||||
const sidebar = ref(null);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@ const addresses = {
|
|||
maker: "0x84addce4fac0b6ee4b0cd132120d6d4b700e35c0",
|
||||
unipool: "0x22bddA39D14eD0aafeee36B6e784602fdDE64723",
|
||||
liquity: "0xDAf2A39503463B0F41f899EDD82213b3c96b6Cf8",
|
||||
reflexer: "0x016ca8d0993d1a7073b01802a2e22fd0df7e633a"
|
||||
reflexer: "0x016ca8d0993d1a7073b01802a2e22fd0df7e633a",
|
||||
yearnV2: "0x3f6DCA8a0b7d04737BC3B2aEAbeB1C09431581f0"
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
"bignumber.js": "^9.0.1",
|
||||
"core-js": "^3.15.1",
|
||||
"css-color-function": "^1.3.3",
|
||||
"dsa-connect": "^0.4.4",
|
||||
"dsa-connect": "^0.4.7-beta.0",
|
||||
"nuxt": "^2.15.7",
|
||||
"qrcode": "^1.4.4",
|
||||
"slugify": "^1.6.0",
|
||||
|
|
|
|||
100
pages/mainnet/yearn-v2.vue
Normal file
100
pages/mainnet/yearn-v2.vue
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
<template>
|
||||
<div>
|
||||
<div>
|
||||
<nuxt-link
|
||||
to="/"
|
||||
class="text-[#C0C5D7] text-lg font-semibold flex items-center"
|
||||
>
|
||||
<BackIcon class="w-4 h-4 mr-3" />
|
||||
Apps
|
||||
</nuxt-link>
|
||||
</div>
|
||||
|
||||
<div class="mt-10 flex items-center justify-between">
|
||||
<div class="flex items-center">
|
||||
<div
|
||||
style="background: radial-gradient(42.15% 42.15% at 48.94% 48.94%, #D6DAE0 75.67%, #F0F3F9 100%), #C4C4C4;"
|
||||
class="w-16 h-16 rounded-full flex items-center justify-center border border-[#CCDCF3]"
|
||||
>
|
||||
<div
|
||||
class="w-12 h-12 rounded-full flex items-center justify-center bg-[#1874FF]"
|
||||
>
|
||||
<CompoundIcon class="w-8 h-8 text-white" />
|
||||
</div>
|
||||
</div>
|
||||
<h1 class="ml-4 text-primary-black text-2xl font-semibold">Yearn</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-[60px]">
|
||||
<div
|
||||
class="w-full flex flex-col mt-6 sm:flex-row sm:items-center sm:justify-between xl:mt-4"
|
||||
>
|
||||
<h2 class="text-primary-gray text-lg font-semibold">Your Positions</h2>
|
||||
|
||||
<div class="mt-4 sm:mt-0 sm:mr-1">
|
||||
<SearchInput
|
||||
v-model.trim="search"
|
||||
dense
|
||||
class="w-[200px]"
|
||||
placeholder="Search positions"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="mt-3 grid w-full grid-cols-1 gap-4 sm:grid-cols-2 xxl:gap-6 min-w-max-content px-1"
|
||||
>
|
||||
<div v-for="item in filteredVaults" :key="item.symbol">
|
||||
<card-yearn
|
||||
:vault="item.address"
|
||||
:token-key="item.token.display_name.toLowerCase()"
|
||||
:supply="item.position.supply"
|
||||
:supply-usd="item.position.supplyUsd"
|
||||
:type="item.type"
|
||||
:price-in-usd="item.priceInUsd"
|
||||
:netAPY="item.apy.net_apy"
|
||||
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, computed } from "@nuxtjs/composition-api";
|
||||
import BackIcon from "~/assets/icons/back.svg?inline";
|
||||
import { useYearnV2Position } from "~/composables/protocols/useYearnV2Position";
|
||||
import { useFormatting } from "~/composables/useFormatting";
|
||||
import { useSearchFilter } from "~/composables/useSearchFilter";
|
||||
import CardYearn from "~/components/protocols/yearn-v2/CardYearn.vue";
|
||||
import CompoundIcon from "~/assets/icons/compound.svg?inline";
|
||||
import ButtonCTAOutlined from "~/components/common/input/ButtonCTAOutlined.vue";
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
BackIcon,
|
||||
CardYearn,
|
||||
CompoundIcon,
|
||||
ButtonCTAOutlined,
|
||||
},
|
||||
setup() {
|
||||
const { vaults } = useYearnV2Position();
|
||||
|
||||
const { formatUsd, formatPercent } = useFormatting();
|
||||
|
||||
const { filtered: filteredVaults, search } = useSearchFilter(
|
||||
vaults,
|
||||
"key",
|
||||
"type"
|
||||
);
|
||||
|
||||
return {
|
||||
filteredVaults,
|
||||
search,
|
||||
formatUsd,
|
||||
formatPercent
|
||||
};
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
|
@ -5919,10 +5919,10 @@ drbg.js@^1.0.1:
|
|||
create-hash "^1.1.2"
|
||||
create-hmac "^1.1.4"
|
||||
|
||||
dsa-connect@^0.4.4:
|
||||
version "0.4.4"
|
||||
resolved "https://registry.yarnpkg.com/dsa-connect/-/dsa-connect-0.4.4.tgz#c47ded36b23d089c85f61bff3a781b5d577d4fe7"
|
||||
integrity sha512-QSR8uiDXRwbInh2muGJfJPEK5KkMRX1Rc5wrcOL3Ov1bKkpZxQ0iSAoO3R/5OD5MV23n6vKiIa9ZX/BVId/exg==
|
||||
dsa-connect@^0.4.7-beta.0:
|
||||
version "0.4.7-beta.0"
|
||||
resolved "https://registry.yarnpkg.com/dsa-connect/-/dsa-connect-0.4.7-beta.0.tgz#40b73e2fdec353c175d2bb3f813a426865940ebb"
|
||||
integrity sha512-pODE4W5KxIx07wmGoV/w1S4hNw6g3GnoNcrDG3ExDRKogIISpqvVfxK+HWkcospmKf9eYoAW1QY0/x32tOxJww==
|
||||
|
||||
duplexer3@^0.1.4:
|
||||
version "0.1.4"
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user