Skip to content

Commit

Permalink
Add support for alternative token out vaults like cmeth
Browse files Browse the repository at this point in the history
  • Loading branch information
philipjames44 committed Nov 5, 2024
1 parent 43c7577 commit 8895d52
Show file tree
Hide file tree
Showing 5 changed files with 372 additions and 13 deletions.
37 changes: 28 additions & 9 deletions src/contexts/v1/BoringVaultContextV1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const SEVEN_SEAS_BASE_API_URL = "https://api.sevenseas.capital";
interface BoringVaultV1ContextProps {
chain: string;
vaultEthersContract: Contract | null;
outputTokenEthersContract: Contract | null;
tellerEthersContract: Contract | null;
accountantEthersContract: Contract | null;
lensEthersContract: Contract | null;
Expand Down Expand Up @@ -123,6 +124,7 @@ const BoringVaultV1Context = createContext<BoringVaultV1ContextProps | null>(

export const BoringVaultV1Provider: React.FC<{
chain: string;
outputTokenContract?: string;
vaultContract: string;
tellerContract: string;
accountantContract: string;
Expand All @@ -139,6 +141,7 @@ export const BoringVaultV1Provider: React.FC<{
}> = ({
children,
chain,
outputTokenContract,
depositTokens,
withdrawTokens,
vaultContract,
Expand Down Expand Up @@ -168,6 +171,8 @@ export const BoringVaultV1Provider: React.FC<{
useState<Contract | null>(null);
const [boringQueueEthersContract, setBoringQueueEthersContract] =
useState<Contract | null>(null);
const [outputTokenEthersContract, setOutputTokenEthersContract] =
useState<Contract | null>(null);

const [baseToken, setBaseToken] = useState<Token | null>(null);

Expand Down Expand Up @@ -249,6 +254,15 @@ export const BoringVaultV1Provider: React.FC<{
setBoringQueueEthersContract(boringQueueEthersContract);
}

if (outputTokenContract) {
const outputTokenEthersContract = new Contract(
outputTokenContract,
erc20Abi,
ethersProvider
);
setOutputTokenEthersContract(outputTokenEthersContract);
}

setVaultEthersContract(vaultEthersContract);
setTellerContract(tellerEthersContract);
setAccountantEthersContract(accountantEthersContract);
Expand Down Expand Up @@ -284,6 +298,7 @@ export const BoringVaultV1Provider: React.FC<{
depositTokens,
withdrawTokens,
delayWithdrawContract,
outputTokenContract,
]);

// Effect to handle updates on acceptedTokens if needed
Expand Down Expand Up @@ -313,7 +328,9 @@ export const BoringVaultV1Provider: React.FC<{

try {
const assets = await lensEthersContract.totalAssets(
vaultContract,
outputTokenEthersContract
? outputTokenEthersContract
: vaultEthersContract,
accountantContract
);
console.log("Total assets from contract: ", assets);
Expand Down Expand Up @@ -353,7 +370,7 @@ export const BoringVaultV1Provider: React.FC<{
try {
const balance = await lensEthersContract.balanceOf(
userAddress,
vaultContract
outputTokenContract ? outputTokenContract : vaultContract
);
console.log("User balance from contract: ", balance);
return Number(balance) / Math.pow(10, decimals!);
Expand Down Expand Up @@ -613,7 +630,7 @@ export const BoringVaultV1Provider: React.FC<{
try {
// First check if the delay withdraw is approved for at least the amount
const vaultContractWithSigner = new Contract(
vaultContract,
outputTokenContract ? outputTokenContract : vaultContract,
BoringVaultABI,
signer
);
Expand Down Expand Up @@ -1031,7 +1048,7 @@ export const BoringVaultV1Provider: React.FC<{
try {
// First check if the delay withdraw is approved for at least the amount
const vaultContractWithSigner = new Contract(
vaultContract,
outputTokenContract ? outputTokenContract : vaultContract,
BoringVaultABI,
signer
);
Expand Down Expand Up @@ -1109,7 +1126,7 @@ export const BoringVaultV1Provider: React.FC<{

const queueTx =
await withdrawQueueContractWithSigner.safeUpdateAtomicRequest(
vaultContract, // offer
outputTokenContract ? outputTokenContract : vaultContract, // offer
token.address, // want
[
deadline.toFixed(0), // Deadline
Expand Down Expand Up @@ -1208,7 +1225,7 @@ export const BoringVaultV1Provider: React.FC<{
// Update request with same token, but 0 amount
const cancelTx =
await withdrawQueueContractWithSigner.updateAtomicRequest(
vaultContract, // Offer
outputTokenContract ? outputTokenContract : vaultContract, // Offer
token.address, // Want
[
0, // Deadline
Expand Down Expand Up @@ -1391,7 +1408,7 @@ export const BoringVaultV1Provider: React.FC<{
try {
// First check if the delay withdraw is approved for at least the amount
const vaultContractWithSigner = new Contract(
vaultContract,
outputTokenContract ? outputTokenContract : vaultContract,
BoringVaultABI,
signer
);
Expand Down Expand Up @@ -1452,7 +1469,7 @@ export const BoringVaultV1Provider: React.FC<{
name: name,
version: '1',
chainId: chainId,
verifyingContract: vaultContract
verifyingContract: outputTokenContract ? outputTokenContract : vaultContract
};

const types = {
Expand Down Expand Up @@ -1557,7 +1574,8 @@ export const BoringVaultV1Provider: React.FC<{
isBoringV1ContextReady,
accountantContract,
boringQueueContract,
vaultContract
vaultContract,
outputTokenContract,
]
);

Expand Down Expand Up @@ -1775,6 +1793,7 @@ export const BoringVaultV1Provider: React.FC<{
value={{
chain,
vaultEthersContract,
outputTokenEthersContract,
tellerEthersContract,
accountantEthersContract,
lensEthersContract,
Expand Down
2 changes: 1 addition & 1 deletion src/examples/v3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ const VaultWidget = () => {
Once you request a withdraw a solver will need to process your request. This can take some time depending on the current queue length and the gas price you are willing to pay. You can check the status of your withdraw request below.
"
buttonText="Withdraw"
popupText="Welcome to the delay withdraw interface!"
popupText="Welcome to the withdraw interface!"
buttonProps={{
colorScheme: "teal",
size: "lg",
Expand Down
13 changes: 13 additions & 0 deletions src/examples/v4.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- src/examples/index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Example Application</title>
</head>
<body>
<div id="root"></div>
<script src="v1.js"></script> <!-- Compiled JavaScript file -->
</body>
</html>
Loading

0 comments on commit 8895d52

Please sign in to comment.