Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add carbon defi in apps #1

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Add carbon defi in apps #1

wants to merge 8 commits into from

Conversation

GrandSchtroumpf
Copy link
Collaborator

Description

Add Carbon Defi as an app.
It should look like that in the UI
zapper-carbon-defi

@wpoulin could you add this to zapper ? 🙏
Also is it possible to add this description in the app page ? I didn't find where is should be set in the code.
"The Ultimate DEX for Onchain Trading & Liquidity"

Checklist

How to test?

Run

pnpm dev

Then check :
http://localhost:5001/apps/carbon-defi/positions?groupIds[]=strategy&network=ethereum
Should display 429 positions, each of them with exactly 2 tokens

http://localhost:5001/apps/carbon-defi/balances?addresses[]=0xb58796c7e02852D46bE2d82c7aCCd4524a43b9dE&networks[]=ethereum
Should have two positions with two tokens inside each

@GrandSchtroumpf
Copy link
Collaborator Author

I'm opening a new comment since both other are outdated.

I managed to used getRawBalances but I'm still relying on position.dataProps.strategy.
I can do it without, but I'm not sure how it would work with keys :

async getRawBalances(address: string): Promise<RawContractPositionBalance[]> {
  if (address === ZERO_ADDRESS) return [];
  const controller = this.getContract();
  const voucher = this.factory.voucher({ address: '', network: Network.ETHEREUM_MAINNET });
  // Get all strategies ids from the user
  const strategyIds = await voucher.read.tokensByOwner([address, BigInt(0), BigInt(0)]);
  const getAllBalances = strategyIds.map(async strategyId => {
    const strategy = await controller.read.strategy([strategyId]);
    return {
      key: '', // Can I use strategyId ?
      tokens: [
        {
          key: '', // What should be here ?
          balance: strategy.orders[0].y.toString(),
        },
        {
          key: '', // What should be here ?
          balance: strategy.orders[1].y.toString(),
        },
      ],
    };
  });
  return Promise.all(getAllBalances);
}

const pairs = await contract.read.pairs();
const getStrategies = pairs.map(pair => contract.read.strategiesByPair([...pair, BigInt(0), BigInt(0)]));
const strategies = await Promise.all(getStrategies).then(matrix => matrix.flat());
return strategies.filter(isActiveStrategy).map(strategy => ({ address, strategy: strategy }));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Essentially, the balances are stil propagated from the definition all the way to dataProps and then balances. The definition should not contain balances

Copy link
Collaborator Author

@GrandSchtroumpf GrandSchtroumpf Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting the definitions (strategies in Carbon) from the contract always returns the balance.
I can remove this information from the dataProps, but I'll have to redo the call to the contract in getBalances
Is that ok ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah okok get it

@wpoulin
Copy link

wpoulin commented Feb 2, 2024

Thanks for your contribution. As you saw/know, studio has been archived 😢 so I'll have to grab your code and add it to our private repo for the app integration to show up. I hope you don't mind

@GrandSchtroumpf
Copy link
Collaborator Author

Sure no problem, thanks for the reviews and explanations. Since I couldn't test with the UI, could you send me a screenshot of the preview when possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants