Skip to content

Add LA Exchange Adapter #14596

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions projects/laexchange/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
async function tvl(api) {
const LAUNCHPOOL_CONTRACT = "0x82Bcfb5695a7E5c3cE2a9f49bFAf6e28BB23F486"
const CURRENCY_ADDRESS = "0xdAC17F958D2ee523a2206206994597C13D831ec7" // USDT

const {currV, TVL } = await api.call({
Copy link
Collaborator

Choose a reason for hiding this comment

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

can use erc20:balanceOf or getBalance instead please?

Copy link
Author

Choose a reason for hiding this comment

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

The contract will create many sub-contracts, and the assets will be stored in the sub-contracts respectively. There is a function dedicated to calculating TVL, which can be obtained directly. The specific contract logic is open source, and you can refer to https://etherscan.io/address/0xf94342d9eb0f42ea6bb6901170db7479e3e88e52#code

    function calcTVL(address currency) public view returns(uint currV, uint TVL) {
        for(uint i=0; i<currencies.length; i++) {
            address curr = currencies[i];
            uint v;
            if(curr == USDX)
                v = totalCurrencyLast[curr];
            else if(curr == USDT || curr == USDC)
                v = totalCurrencyLast[curr].mul(1e18/1e6);
            else if(curr == WETH)
                v = totalCurrencyLast[curr].mul(uint(AggregatorInterface(oracleETH).latestAnswer())).div(1e8);
            TVL = TVL.add(v);
            if(curr == currency)
                currV = v;
        }
    }

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we fetch a list of subcontracts from an API and then use erc20:balanceOf?

Copy link
Author

Choose a reason for hiding this comment

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

Of course we can, but using the server's API will make it more centralized. We prefer an open source and decentralized approach.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We cant use calcTVL()

Copy link
Author

Choose a reason for hiding this comment

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

Could you please explain why?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Because it doesnt give us a breakdown of assets held

Copy link
Author

Choose a reason for hiding this comment

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

totalCurrencyLast is just for the convenience of making a statistical calculation of funds. Its underlying change logic is deposit and withdraw. We will update it at a reasonable position.

    function deposit(uint value) external payable invest(msg.sender) {
        uint amount;
        if(totalSupply == 0)
            amount = value;
        else if(totalCurrencyLast == 0) {        // Finished
            if(msg.value > 0)
                msg.sender.transfer(msg.value);
            return;
        } else
            amount = value.mul(totalSupply).div(totalCurrencyLast);
        if(msg.value >= value && currency == router.WETH())
            IWETH(currency).deposit.value(msg.value)();
        else {
            currency.safeTransferFrom(msg.sender, address(this), value);
            if(msg.value > 0)
                msg.sender.transfer(msg.value);
        }
        balanceOf[msg.sender] = balanceOf[msg.sender].add(amount);
        totalSupply = totalSupply.add(amount);
        totalCurrencyLast  = totalCurrencyLast.add(value);
        lasttimeDepositOf[msg.sender] = now;
        emit Transfer(address(0), msg.sender, amount);
        emit Deposited(msg.sender, value);
    }
    event Deposited(address indexed account, uint value);
    event Transfer(address indexed from, address indexed to, uint value);

    function withdraw(uint value) public invest(msg.sender) returns (uint, uint) {
        uint amount = value.mul(totalSupply).div1(totalCurrencyLast);
        if(amount > balanceOf[msg.sender]) {
            amount = balanceOf[msg.sender];
            value = currencyOf(msg.sender);
        }
        balanceOf[msg.sender] = balanceOf[msg.sender].sub(amount);
        totalSupply = totalSupply.sub(amount);
        emit Transfer(msg.sender, address(0), amount);
        totalCurrencyLast  = totalCurrencyLast.sub(value);

        uint tax = lasttimeDepositOf[msg.sender].add(withdrawTaxSpan) <= now ? 0 : value.mul(withdrawTaxRate).div(1 ether);
        currency.safeTransfer(address(router), tax);
        IUniswapV2Callee(address(router)).uniswapV2Call(underlying, uint(currency), tax, "");
        value = value.sub(tax);

        if(currency == router.WETH()) {
            IWETH(currency).withdraw(value);
            msg.sender.transfer(value);
        } else
            currency.safeTransfer(msg.sender, value);
        emit Withdrawn(msg.sender, value, tax);
        return (value, tax);
    }
    event Withdrawn(address indexed account, uint value, uint tax);

If this is unacceptable, do I need to write a set of APIs to return a bunch of addresses and then balanceOf?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ideally we would use balanceOf across a list of holder addresses yeah

target: LAUNCHPOOL_CONTRACT,
abi: 'function calcTVL(address currency) view returns (uint256 currV, uint256 TVL)',
params: [CURRENCY_ADDRESS]
})
api.addToken(CURRENCY_ADDRESS, TVL)
return {
'ethereum': TVL
}
}

module.exports = {
methodology: 'Calculates the total amount of ETH, USDT, USDC, and USDX deposited across various pools',
misrepresentedTokens: true,
ethereum: {
tvl
}
}
Loading