Skip to content

Commit

Permalink
Merge pull request #72 from Jeff-CCH/feat/add-polygon-zkevm-protocols
Browse files Browse the repository at this point in the history
Feat/add polygon zkevm protocols
  • Loading branch information
Jeff-CCH authored Jul 26, 2024
2 parents 09d5ab6 + 08874db commit a26d59c
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 96 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilly-bees-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@protocolink/logics': minor
---

add Polygon zkevm to Paraswap
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
},
"dependencies": {
"@paraswap/sdk": "^6.6.0",
"@protocolink/common": "^0.4.2",
"@protocolink/core": "^0.5.1",
"@protocolink/common": "^0.5.1",
"@protocolink/core": "^0.6.0",
"@protocolink/smart-accounts": "^0.1.4",
"@types/lodash": "^4.14.195",
"@uniswap/sdk": "^3.0.3",
Expand Down
3 changes: 1 addition & 2 deletions src/logics/balancer-v2/logic.flash-loan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import * as common from '@protocolink/common';
import { constants, utils } from 'ethers';
import { expect } from 'chai';
import { getContractAddress } from './configs';
import { mainnetTokens } from '@protocolink/test-helpers';

describe('BalancerV2 FlashLoanLogic', function () {
context('Test getTokenList', async function () {
Expand All @@ -26,7 +25,7 @@ describe('BalancerV2 FlashLoanLogic', function () {
const testCases: LogicTestCase<FlashLoanLogicFields>[] = [
{
fields: {
loans: new common.TokenAmounts([mainnetTokens.WETH, '1'], [mainnetTokens.USDC, '1']),
loans: new common.TokenAmounts([common.mainnetTokens.WETH, '1'], [common.mainnetTokens.USDC, '1']),
params: '0x',
},
},
Expand Down
9 changes: 4 additions & 5 deletions src/logics/compound-v2/logic.repay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import * as common from '@protocolink/common';
import { constants, utils } from 'ethers';
import * as core from '@protocolink/core';
import { expect } from 'chai';
import { mainnetTokens } from '@protocolink/test-helpers';
import { toCToken } from './configs';

describe('CompoundV2 RepayLogic', function () {
Expand All @@ -29,26 +28,26 @@ describe('CompoundV2 RepayLogic', function () {
{
fields: {
borrower: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa',
input: new common.TokenAmount(mainnetTokens.ETH, '1'),
input: new common.TokenAmount(common.mainnetTokens.ETH, '1'),
},
},
{
fields: {
borrower: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa',
input: new common.TokenAmount(mainnetTokens.USDC, '1'),
input: new common.TokenAmount(common.mainnetTokens.USDC, '1'),
},
},
{
fields: {
borrower: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa',
input: new common.TokenAmount(mainnetTokens.ETH, '1'),
input: new common.TokenAmount(common.mainnetTokens.ETH, '1'),
balanceBps: 5000,
},
},
{
fields: {
borrower: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa',
input: new common.TokenAmount(mainnetTokens.USDC, '1'),
input: new common.TokenAmount(common.mainnetTokens.USDC, '1'),
balanceBps: 5000,
},
},
Expand Down
17 changes: 8 additions & 9 deletions src/logics/compound-v2/logic.supply.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import * as common from '@protocolink/common';
import { constants, utils } from 'ethers';
import * as core from '@protocolink/core';
import { expect } from 'chai';
import { mainnetTokens } from '@protocolink/test-helpers';
import { toCToken } from './configs';

describe('CompoundV2 SupplyLogic', function () {
Expand All @@ -28,27 +27,27 @@ describe('CompoundV2 SupplyLogic', function () {
const testCases: LogicTestCase<SupplyLogicFields>[] = [
{
fields: {
input: new common.TokenAmount(mainnetTokens.ETH, '1'),
output: new common.TokenAmount(toCToken(mainnetTokens.ETH), '0'),
input: new common.TokenAmount(common.mainnetTokens.ETH, '1'),
output: new common.TokenAmount(toCToken(common.mainnetTokens.ETH), '0'),
},
},
{
fields: {
input: new common.TokenAmount(mainnetTokens.USDC, '1'),
output: new common.TokenAmount(toCToken(mainnetTokens.USDC), '0'),
input: new common.TokenAmount(common.mainnetTokens.USDC, '1'),
output: new common.TokenAmount(toCToken(common.mainnetTokens.USDC), '0'),
},
},
{
fields: {
input: new common.TokenAmount(mainnetTokens.ETH, '1'),
output: new common.TokenAmount(toCToken(mainnetTokens.ETH), '0'),
input: new common.TokenAmount(common.mainnetTokens.ETH, '1'),
output: new common.TokenAmount(toCToken(common.mainnetTokens.ETH), '0'),
balanceBps: 5000,
},
},
{
fields: {
input: new common.TokenAmount(mainnetTokens.USDC, '1'),
output: new common.TokenAmount(toCToken(mainnetTokens.USDC), '0'),
input: new common.TokenAmount(common.mainnetTokens.USDC, '1'),
output: new common.TokenAmount(toCToken(common.mainnetTokens.USDC), '0'),
balanceBps: 5000,
},
},
Expand Down
17 changes: 8 additions & 9 deletions src/logics/compound-v2/logic.withdraw.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import * as common from '@protocolink/common';
import { constants, utils } from 'ethers';
import * as core from '@protocolink/core';
import { expect } from 'chai';
import { mainnetTokens } from '@protocolink/test-helpers';
import { toCToken } from './configs';

describe('CompoundV2 WithdrawLogic', function () {
Expand All @@ -27,27 +26,27 @@ describe('CompoundV2 WithdrawLogic', function () {
const testCases: LogicTestCase<WithdrawLogicFields>[] = [
{
fields: {
input: new common.TokenAmount(toCToken(mainnetTokens.ETH), '1'),
output: new common.TokenAmount(mainnetTokens.ETH, '0'),
input: new common.TokenAmount(toCToken(common.mainnetTokens.ETH), '1'),
output: new common.TokenAmount(common.mainnetTokens.ETH, '0'),
},
},
{
fields: {
input: new common.TokenAmount(toCToken(mainnetTokens.USDC), '1'),
output: new common.TokenAmount(mainnetTokens.USDC, '0'),
input: new common.TokenAmount(toCToken(common.mainnetTokens.USDC), '1'),
output: new common.TokenAmount(common.mainnetTokens.USDC, '0'),
},
},
{
fields: {
input: new common.TokenAmount(toCToken(mainnetTokens.ETH), '1'),
output: new common.TokenAmount(mainnetTokens.ETH, '0'),
input: new common.TokenAmount(toCToken(common.mainnetTokens.ETH), '1'),
output: new common.TokenAmount(common.mainnetTokens.ETH, '0'),
balanceBps: 5000,
},
},
{
fields: {
input: new common.TokenAmount(toCToken(mainnetTokens.USDC), '1'),
output: new common.TokenAmount(mainnetTokens.USDC, '0'),
input: new common.TokenAmount(toCToken(common.mainnetTokens.USDC), '1'),
output: new common.TokenAmount(common.mainnetTokens.USDC, '0'),
balanceBps: 5000,
},
},
Expand Down
5 changes: 5 additions & 0 deletions src/logics/paraswap-v5/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export const configs: Config[] = [
'https://tokens.coingecko.com/polygon-pos/all.json',
],
},
{
chainId: common.ChainId.polygonZkevm,
tokenTransferProxyAddress: '0xC8a21FcD5A100c3ecc037c97e2f9C53a8D3A02A1',
tokenListUrls: ['https://unpkg.com/quickswap-default-token-list@latest/build/quickswap-default.tokenlist.json'],
},
{
chainId: common.ChainId.base,
tokenTransferProxyAddress: '0x93aAAe79a53759cD164340E4C8766E4Db5331cD7',
Expand Down
13 changes: 6 additions & 7 deletions src/logics/paraswap-v5/logic.swap-token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { constants, utils } from 'ethers';
import * as core from '@protocolink/core';
import { expect } from 'chai';
import { getTokenListUrls, getTokenTransferProxyAddress } from './configs';
import { mainnetTokens } from '@protocolink/test-helpers';

describe('ParaswapV5 SwapTokenLogic', function () {
context('Test getTokenListUrls', function () {
Expand All @@ -32,26 +31,26 @@ describe('ParaswapV5 SwapTokenLogic', function () {
{
chainId: common.ChainId.mainnet,
fields: {
input: new common.TokenAmount(mainnetTokens.ETH, '1'),
output: new common.TokenAmount(mainnetTokens.USDC, '0'),
input: new common.TokenAmount(common.mainnetTokens.ETH, '1'),
output: new common.TokenAmount(common.mainnetTokens.USDC, '0'),
slippage: 500,
},
options: { account: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa' },
},
{
chainId: common.ChainId.mainnet,
fields: {
input: new common.TokenAmount(mainnetTokens.USDC, '1'),
output: new common.TokenAmount(mainnetTokens.ETH, '0'),
input: new common.TokenAmount(common.mainnetTokens.USDC, '1'),
output: new common.TokenAmount(common.mainnetTokens.ETH, '0'),
slippage: 500,
},
options: { account: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa' },
},
{
chainId: common.ChainId.mainnet,
fields: {
input: new common.TokenAmount(mainnetTokens.USDC, '1'),
output: new common.TokenAmount(mainnetTokens.DAI, '0'),
input: new common.TokenAmount(common.mainnetTokens.USDC, '1'),
output: new common.TokenAmount(common.mainnetTokens.DAI, '0'),
slippage: 500,
},
options: { account: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa' },
Expand Down
3 changes: 1 addition & 2 deletions src/logics/permit2/logic.pull-token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as common from '@protocolink/common';
import { constants, utils } from 'ethers';
import * as core from '@protocolink/core';
import { expect } from 'chai';
import { mainnetTokens } from '@protocolink/test-helpers';

describe('Permit2 PullTokenLogic', function () {
context('Test getTokenList', async function () {
Expand All @@ -26,7 +25,7 @@ describe('Permit2 PullTokenLogic', function () {
const iface = routerKit.permit2Iface;

const testCases: LogicTestCase<PullTokenLogicFields>[] = [
{ fields: { input: new common.TokenAmount(mainnetTokens.WETH, '1') } },
{ fields: { input: new common.TokenAmount(common.mainnetTokens.WETH, '1') } },
];

testCases.forEach(({ fields }, i) => {
Expand Down
49 changes: 24 additions & 25 deletions src/logics/uniswap-v3/logic.swap-token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { constants, utils } from 'ethers';
import * as core from '@protocolink/core';
import { expect } from 'chai';
import { getConfig } from './configs';
import { mainnetTokens } from '@protocolink/test-helpers';
import * as univ3 from 'src/modules/univ3';

describe('UniswapV3 SwapTokenLogic', function () {
Expand All @@ -29,8 +28,8 @@ describe('UniswapV3 SwapTokenLogic', function () {
{
fields: {
tradeType: core.TradeType.exactIn,
input: new common.TokenAmount(mainnetTokens.ETH, '1'),
output: new common.TokenAmount(mainnetTokens.USDC, '1661.098116'),
input: new common.TokenAmount(common.mainnetTokens.ETH, '1'),
output: new common.TokenAmount(common.mainnetTokens.USDC, '1661.098116'),
fee: 500,
slippage: 100,
},
Expand All @@ -39,8 +38,8 @@ describe('UniswapV3 SwapTokenLogic', function () {
{
fields: {
tradeType: core.TradeType.exactIn,
input: new common.TokenAmount(mainnetTokens.ETH, '1'),
output: new common.TokenAmount(mainnetTokens.USDC, '1661.098116'),
input: new common.TokenAmount(common.mainnetTokens.ETH, '1'),
output: new common.TokenAmount(common.mainnetTokens.USDC, '1661.098116'),
path: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc20001f42260fac5e5542a773aa44fbcfedf7c193bc2c5990001f4a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
slippage: 100,
},
Expand All @@ -49,8 +48,8 @@ describe('UniswapV3 SwapTokenLogic', function () {
{
fields: {
tradeType: core.TradeType.exactIn,
input: new common.TokenAmount(mainnetTokens.USDC, '1000'),
output: new common.TokenAmount(mainnetTokens.ETH, '0.608027615305460657'),
input: new common.TokenAmount(common.mainnetTokens.USDC, '1000'),
output: new common.TokenAmount(common.mainnetTokens.ETH, '0.608027615305460657'),
fee: 500,
slippage: 100,
},
Expand All @@ -59,8 +58,8 @@ describe('UniswapV3 SwapTokenLogic', function () {
{
fields: {
tradeType: core.TradeType.exactIn,
input: new common.TokenAmount(mainnetTokens.USDC, '1000'),
output: new common.TokenAmount(mainnetTokens.ETH, '0.608027615305460657'),
input: new common.TokenAmount(common.mainnetTokens.USDC, '1000'),
output: new common.TokenAmount(common.mainnetTokens.ETH, '0.608027615305460657'),
path: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb480001f42260fac5e5542a773aa44fbcfedf7c193bc2c5990001f4c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
slippage: 100,
},
Expand All @@ -69,8 +68,8 @@ describe('UniswapV3 SwapTokenLogic', function () {
{
fields: {
tradeType: core.TradeType.exactIn,
input: new common.TokenAmount(mainnetTokens.USDC, '1000'),
output: new common.TokenAmount(mainnetTokens.DAI, '1000'),
input: new common.TokenAmount(common.mainnetTokens.USDC, '1000'),
output: new common.TokenAmount(common.mainnetTokens.DAI, '1000'),
fee: 500,
slippage: 100,
},
Expand All @@ -79,8 +78,8 @@ describe('UniswapV3 SwapTokenLogic', function () {
{
fields: {
tradeType: core.TradeType.exactIn,
input: new common.TokenAmount(mainnetTokens.USDC, '1000'),
output: new common.TokenAmount(mainnetTokens.DAI, '1000'),
input: new common.TokenAmount(common.mainnetTokens.USDC, '1000'),
output: new common.TokenAmount(common.mainnetTokens.DAI, '1000'),
path: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb480001f42260fac5e5542a773aa44fbcfedf7c193bc2c5990001f46b175474e89094c44da98b954eedeac495271d0f',
slippage: 100,
},
Expand All @@ -89,53 +88,53 @@ describe('UniswapV3 SwapTokenLogic', function () {
{
fields: {
tradeType: core.TradeType.exactOut,
input: new common.TokenAmount(mainnetTokens.ETH, '0.608027615305460657'),
output: new common.TokenAmount(mainnetTokens.USDC, '1000'),
input: new common.TokenAmount(common.mainnetTokens.ETH, '0.608027615305460657'),
output: new common.TokenAmount(common.mainnetTokens.USDC, '1000'),
fee: 500,
},
options: { account: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa' },
},
{
fields: {
tradeType: core.TradeType.exactOut,
input: new common.TokenAmount(mainnetTokens.ETH, '0.608027615305460657'),
output: new common.TokenAmount(mainnetTokens.USDC, '1000'),
input: new common.TokenAmount(common.mainnetTokens.ETH, '0.608027615305460657'),
output: new common.TokenAmount(common.mainnetTokens.USDC, '1000'),
path: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc20001f42260fac5e5542a773aa44fbcfedf7c193bc2c5990001f4a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
},
options: { account: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa' },
},
{
fields: {
tradeType: core.TradeType.exactOut,
input: new common.TokenAmount(mainnetTokens.USDC, '1000'),
output: new common.TokenAmount(mainnetTokens.ETH, '0.608027615305460657'),
input: new common.TokenAmount(common.mainnetTokens.USDC, '1000'),
output: new common.TokenAmount(common.mainnetTokens.ETH, '0.608027615305460657'),
fee: 500,
},
options: { account: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa' },
},
{
fields: {
tradeType: core.TradeType.exactOut,
input: new common.TokenAmount(mainnetTokens.USDC, '1000'),
output: new common.TokenAmount(mainnetTokens.ETH, '0.608027615305460657'),
input: new common.TokenAmount(common.mainnetTokens.USDC, '1000'),
output: new common.TokenAmount(common.mainnetTokens.ETH, '0.608027615305460657'),
path: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb480001f42260fac5e5542a773aa44fbcfedf7c193bc2c5990001f4c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
},
options: { account: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa' },
},
{
fields: {
tradeType: core.TradeType.exactOut,
input: new common.TokenAmount(mainnetTokens.USDC, '1000'),
output: new common.TokenAmount(mainnetTokens.DAI, '1000'),
input: new common.TokenAmount(common.mainnetTokens.USDC, '1000'),
output: new common.TokenAmount(common.mainnetTokens.DAI, '1000'),
fee: 500,
},
options: { account: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa' },
},
{
fields: {
tradeType: core.TradeType.exactOut,
input: new common.TokenAmount(mainnetTokens.USDC, '1000'),
output: new common.TokenAmount(mainnetTokens.DAI, '1000'),
input: new common.TokenAmount(common.mainnetTokens.USDC, '1000'),
output: new common.TokenAmount(common.mainnetTokens.DAI, '1000'),
path: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb480001f42260fac5e5542a773aa44fbcfedf7c193bc2c5990001f4c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
},
options: { account: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa' },
Expand Down
Loading

0 comments on commit a26d59c

Please sign in to comment.