Skip to content

Commit

Permalink
fix: token configs of compound v3 and morphoblue
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob Lu authored and LuPoYi committed Jun 19, 2024
1 parent dc92ad4 commit 2eb924d
Show file tree
Hide file tree
Showing 32 changed files with 308 additions and 167 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-wombats-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@protocolink/logics': patch
---

fix token configs of compound v3 and morphoblue
75 changes: 26 additions & 49 deletions src/logics/compound-v3/configs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { arbitrumTokens, baseTokens, mainnetTokens, optimismTokens, polygonTokens } from './tokens';
import * as common from '@protocolink/common';

type ContractNames = 'CometRewards';
Expand All @@ -11,8 +12,8 @@ export enum MarketId {

export interface MarketConfig {
id: string;
cometAddress: string;
baseTokenAddress: string;
comet: common.Token;
baseToken: common.Token;
}

export interface Config {
Expand All @@ -31,22 +32,16 @@ export const configs: Config[] = [
markets: [
{
id: MarketId.USDC,
cometAddress: '0xc3d688B66703497DAA19211EEdff47f25384cdc3',
baseTokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
comet: mainnetTokens.cUSDCv3,
baseToken: mainnetTokens.USDC,
},
{
id: MarketId.ETH,
cometAddress: '0xA17581A9E3356d9A858b789D68B4d866e593aE94',
baseTokenAddress: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
comet: mainnetTokens.cWETHv3,
baseToken: mainnetTokens.WETH,
},
],
COMP: new common.Token(
common.ChainId.mainnet,
'0xc00e94Cb662C3520282E6f5717214004A7f26888',
18,
'COMP',
'Compound'
),
COMP: mainnetTokens.COMP,
},
{
chainId: common.ChainId.optimism,
Expand All @@ -56,17 +51,11 @@ export const configs: Config[] = [
markets: [
{
id: MarketId.USDC,
cometAddress: '0x2e44e174f7D53F0212823acC11C01A11d58c5bCB',
baseTokenAddress: '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85',
comet: optimismTokens.cUSDCv3,
baseToken: optimismTokens.USDC,
},
],
COMP: new common.Token(
common.ChainId.optimism,
'0x7e7d4467112689329f7E06571eD0E8CbAd4910eE',
18,
'COMP',
'Compound'
),
COMP: optimismTokens.COMP,
},
{
chainId: common.ChainId.polygon,
Expand All @@ -76,17 +65,11 @@ export const configs: Config[] = [
markets: [
{
id: MarketId.USDCe,
cometAddress: '0xF25212E676D1F7F89Cd72fFEe66158f541246445',
baseTokenAddress: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
comet: polygonTokens.cUSDCv3,
baseToken: polygonTokens['USDC.e'],
},
],
COMP: new common.Token(
common.ChainId.polygon,
'0x8505b9d2254A7Ae468c0E9dd10Ccea3A837aef5c',
18,
'COMP',
'(PoS) Compound'
),
COMP: polygonTokens.COMP,
},
{
chainId: common.ChainId.base,
Expand All @@ -96,21 +79,21 @@ export const configs: Config[] = [
markets: [
{
id: MarketId.USDC,
cometAddress: '0xb125E6687d4313864e53df431d5425969c15Eb2F',
baseTokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
comet: baseTokens.cUSDCv3,
baseToken: baseTokens.USDC,
},
{
id: MarketId.USDbC,
cometAddress: '0x9c4ec768c28520B50860ea7a15bd7213a9fF58bf',
baseTokenAddress: '0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA',
comet: baseTokens.cUSDbCv3,
baseToken: baseTokens.USDbC,
},
{
id: MarketId.ETH,
cometAddress: '0x46e6b214b524310239732D51387075E0e70970bf',
baseTokenAddress: '0x4200000000000000000000000000000000000006',
comet: baseTokens.cWETHv3,
baseToken: baseTokens.WETH,
},
],
COMP: new common.Token(common.ChainId.base, '0x9e1028F5F1D5eDE59748FFceE5532509976840E0', 18, 'COMP', 'Compound'),
COMP: baseTokens.COMP,
},
{
chainId: common.ChainId.arbitrum,
Expand All @@ -120,22 +103,16 @@ export const configs: Config[] = [
markets: [
{
id: MarketId.USDCe,
cometAddress: '0xA5EDBDD9646f8dFF606d7448e414884C7d905dCA',
baseTokenAddress: '0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8',
comet: arbitrumTokens.cUSDCev3,
baseToken: arbitrumTokens['USDC.e'],
},
{
id: MarketId.USDC,
cometAddress: '0x9c4ec768c28520B50860ea7a15bd7213a9fF58bf',
baseTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
comet: arbitrumTokens.cUSDCv3,
baseToken: arbitrumTokens.USDC,
},
],
COMP: new common.Token(
common.ChainId.arbitrum,
'0x354A6dA3fcde098F8389cad84b0182725c6C91dE',
18,
'COMP',
'Compound'
),
COMP: arbitrumTokens.COMP,
},
];

Expand Down
2 changes: 1 addition & 1 deletion src/logics/compound-v3/logic.borrow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('CompoundV3 BorrowLogic', function () {
const { marketId, output } = fields;
const market = getMarket(chainId, marketId);

expect(routerLogic.to).to.eq(market.cometAddress);
expect(routerLogic.to).to.eq(market.comet.address);
expect(utils.isBytesLike(routerLogic.data)).to.be.true;
expect(sig).to.eq(iface.getSighash('withdrawFrom'));
expect(routerLogic.inputs).to.deep.eq([]);
Expand Down
2 changes: 1 addition & 1 deletion src/logics/compound-v3/logic.borrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class BorrowLogic extends core.Logic implements core.LogicTokenListInterf
const tokenOut = output.token.wrapped;
const agent = await this.calcAgent(account);

const to = market.cometAddress;
const to = market.comet.address;
const data = Comet__factory.createInterface().encodeFunctionData('withdrawFrom', [
account,
agent,
Expand Down
4 changes: 2 additions & 2 deletions src/logics/compound-v3/logic.claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ export class ClaimLogic
if (owner === account) {
const agent = await this.calcAgent(account);
data = CometRewards__factory.createInterface().encodeFunctionData('claimTo', [
market.cometAddress,
market.comet.address,
owner,
agent,
true,
]);
} else {
data = CometRewards__factory.createInterface().encodeFunctionData('claim', [market.cometAddress, owner, true]);
data = CometRewards__factory.createInterface().encodeFunctionData('claim', [market.comet.address, owner, true]);
}

return core.newLogic({ to, data });
Expand Down
2 changes: 1 addition & 1 deletion src/logics/compound-v3/logic.repay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('CompoundV3 RepayLogic', function () {
const { marketId, input, balanceBps } = fields;
const market = getMarket(chainId, marketId);

expect(routerLogic.to).to.eq(market.cometAddress);
expect(routerLogic.to).to.eq(market.comet.address);
expect(utils.isBytesLike(routerLogic.data)).to.be.true;
expect(sig).to.eq(iface.getSighash('supplyTo'));
expect(routerLogic.inputs[0].token).to.eq(input.token.wrapped.address);
Expand Down
2 changes: 1 addition & 1 deletion src/logics/compound-v3/logic.repay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class RepayLogic extends core.Logic implements core.LogicTokenListInterfa
const borrowBalance = await service.getBorrowBalance(marketId, borrower, tokenIn);
const repayAll = input.gte(borrowBalance);

const to = market.cometAddress;
const to = market.comet.address;
const data = Comet__factory.createInterface().encodeFunctionData('supplyTo', [
borrower,
tokenIn.address,
Expand Down
2 changes: 1 addition & 1 deletion src/logics/compound-v3/logic.supply-base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('CompoundV3 SupplyBaseLogic', function () {
const { marketId, input, balanceBps } = fields;
const market = getMarket(chainId, marketId);

expect(routerLogic.to).to.eq(market.cometAddress);
expect(routerLogic.to).to.eq(market.comet.address);
expect(utils.isBytesLike(routerLogic.data)).to.be.true;
expect(sig).to.eq(iface.getSighash('supply'));
expect(routerLogic.inputs[0].token).to.eq(input.token.wrapped.address);
Expand Down
2 changes: 1 addition & 1 deletion src/logics/compound-v3/logic.supply-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class SupplyBaseLogic
const market = getMarket(this.chainId, marketId);
const tokenIn = input.token.wrapped;

const to = market.cometAddress;
const to = market.comet.address;
const data = Comet__factory.createInterface().encodeFunctionData('supply', [tokenIn.address, input.amountWei]);
const amountOffset = balanceBps ? common.getParamOffset(1) : undefined;
const inputs = [
Expand Down
2 changes: 1 addition & 1 deletion src/logics/compound-v3/logic.supply-collateral.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('CompoundV3 SupplyCollateralLogic', function () {
const { marketId, input, balanceBps } = fields;
const market = getMarket(chainId, marketId);

expect(routerLogic.to).to.eq(market.cometAddress);
expect(routerLogic.to).to.eq(market.comet.address);
expect(utils.isBytesLike(routerLogic.data)).to.be.true;
expect(sig).to.eq(iface.getSighash('supplyTo'));
expect(routerLogic.inputs[0].token).to.eq(input.token.wrapped.address);
Expand Down
2 changes: 1 addition & 1 deletion src/logics/compound-v3/logic.supply-collateral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class SupplyCollateralLogic
const market = getMarket(this.chainId, marketId);
const tokenIn = input.token.wrapped;

const to = market.cometAddress;
const to = market.comet.address;
const data = Comet__factory.createInterface().encodeFunctionData('supplyTo', [
account,
tokenIn.address,
Expand Down
2 changes: 1 addition & 1 deletion src/logics/compound-v3/logic.withdraw-base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('CompoundV3 WithdrawBaseLogic', function () {
const { marketId, input, output, balanceBps } = fields;
const market = getMarket(chainId, marketId);

expect(routerLogic.to).to.eq(market.cometAddress);
expect(routerLogic.to).to.eq(market.comet.address);
expect(utils.isBytesLike(routerLogic.data)).to.be.true;
expect(sig).to.eq(iface.getSighash('withdraw'));
if (balanceBps) {
Expand Down
2 changes: 1 addition & 1 deletion src/logics/compound-v3/logic.withdraw-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class WithdrawBaseLogic
const market = getMarket(this.chainId, marketId);
const tokenOut = output.token.wrapped;

const to = market.cometAddress;
const to = market.comet.address;
const data = Comet__factory.createInterface().encodeFunctionData('withdraw', [tokenOut.address, input.amountWei]);
const amountOffset = balanceBps ? common.getParamOffset(1) : undefined;
const inputs = [core.newLogicInput({ input, balanceBps, amountOffset })];
Expand Down
2 changes: 1 addition & 1 deletion src/logics/compound-v3/logic.withdraw-collateral.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('CompoundV3 WithdrawCollateralLogic', function () {
const { marketId, output } = fields;
const market = getMarket(chainId, marketId);

expect(routerLogic.to).to.eq(market.cometAddress);
expect(routerLogic.to).to.eq(market.comet.address);
expect(utils.isBytesLike(routerLogic.data)).to.be.true;
expect(sig).to.eq(iface.getSighash('withdrawFrom'));
expect(routerLogic.inputs).to.deep.eq([]);
Expand Down
2 changes: 1 addition & 1 deletion src/logics/compound-v3/logic.withdraw-collateral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class WithdrawCollateralLogic
const tokenOut = output.token.wrapped;
const agent = await this.calcAgent(account);

const to = market.cometAddress;
const to = market.comet.address;
const data = Comet__factory.createInterface().encodeFunctionData('withdrawFrom', [
account,
agent,
Expand Down
26 changes: 13 additions & 13 deletions src/logics/compound-v3/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@ import * as common from '@protocolink/common';
export class Service extends common.Web3Toolkit {
async getCToken(marketId: string) {
const market = getMarket(this.chainId, marketId);
const cToken = await this.getToken(market.cometAddress);
const cToken = await this.getToken(market.comet.address);

return cToken;
}

async getBaseToken(marketId: string) {
const market = getMarket(this.chainId, marketId);
const baseToken = await this.getToken(market.baseTokenAddress);
const baseToken = await this.getToken(market.baseToken.address);

return baseToken;
}

async getCometTokens(marketId: string) {
const market = getMarket(this.chainId, marketId);
const tokens = await this.getTokens([market.cometAddress, market.baseTokenAddress]);
const tokens = await this.getTokens([market.comet.address, market.baseToken.address]);

return { cToken: tokens[0], baseToken: tokens[1] };
}

async getCollaterals(marketId: string) {
const market = getMarket(this.chainId, marketId);
const numAssets = await Comet__factory.connect(market.cometAddress, this.provider).numAssets();
const numAssets = await Comet__factory.connect(market.comet.address, this.provider).numAssets();

const iface = Comet__factory.createInterface();
const calls: common.Multicall3.CallStruct[] = [];
for (let i = 0; i < numAssets; i++) {
calls.push({ target: market.cometAddress, callData: iface.encodeFunctionData('getAssetInfo', [i]) });
calls.push({ target: market.comet.address, callData: iface.encodeFunctionData('getAssetInfo', [i]) });
}
const { returnData } = await this.multicall3.callStatic.aggregate(calls);

Expand All @@ -50,14 +50,14 @@ export class Service extends common.Web3Toolkit {

async isAllowed(marketId: string, owner: string, manager: string) {
const market = getMarket(this.chainId, marketId);
const isAllowed = await Comet__factory.connect(market.cometAddress, this.provider).isAllowed(owner, manager);
const isAllowed = await Comet__factory.connect(market.comet.address, this.provider).isAllowed(owner, manager);

return isAllowed;
}

buildAllowTransactionRequest(marketId: string, manager: string, isAllowed: boolean): common.TransactionRequest {
const market = getMarket(this.chainId, marketId);
const to = market.cometAddress;
const to = market.comet.address;
const iface = Comet__factory.createInterface();
const data = iface.encodeFunctionData('allow', [manager, isAllowed]);

Expand All @@ -66,7 +66,7 @@ export class Service extends common.Web3Toolkit {

async getCollateralBalance(marketId: string, account: string, asset: common.Token) {
const market = getMarket(this.chainId, marketId);
const collateralBalance = await Comet__factory.connect(market.cometAddress, this.provider).collateralBalanceOf(
const collateralBalance = await Comet__factory.connect(market.comet.address, this.provider).collateralBalanceOf(
account,
asset.wrapped.address
);
Expand All @@ -79,7 +79,7 @@ export class Service extends common.Web3Toolkit {
if (!baseToken) {
baseToken = await this.getBaseToken(market.id);
}
const borrowBalance = await Comet__factory.connect(market.cometAddress, this.provider).borrowBalanceOf(borrower);
const borrowBalance = await Comet__factory.connect(market.comet.address, this.provider).borrowBalanceOf(borrower);

return new common.TokenAmount(baseToken).setWei(borrowBalance);
}
Expand All @@ -89,7 +89,7 @@ export class Service extends common.Web3Toolkit {
if (!baseToken) {
baseToken = await this.getBaseToken(market.id);
}
const userBasic = await Comet__factory.connect(market.cometAddress, this.provider).userBasic(account);
const userBasic = await Comet__factory.connect(market.comet.address, this.provider).userBasic(account);

return new common.TokenAmount(baseToken).setWei(userBasic.principal);
}
Expand All @@ -99,7 +99,7 @@ export class Service extends common.Web3Toolkit {
const { owed } = await CometRewards__factory.connect(
getContractAddress(this.chainId, 'CometRewards'),
this.provider
).callStatic.getRewardOwed(market.cometAddress, owner);
).callStatic.getRewardOwed(market.comet.address, owner);

return new common.TokenAmount(COMP(this.chainId)).setWei(owed);
}
Expand All @@ -111,11 +111,11 @@ export class Service extends common.Web3Toolkit {
const iface = Comet__factory.createInterface();
const calls: common.Multicall3.CallStruct[] = [
{
target: market.cometAddress,
target: market.comet.address,
callData: iface.encodeFunctionData('getAssetInfoByAddress', [asset]),
},
{
target: market.cometAddress,
target: market.comet.address,
callData: iface.encodeFunctionData('totalsCollateral', [asset]),
},
];
Expand Down
Loading

0 comments on commit 2eb924d

Please sign in to comment.