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 OpenOcean v2 test #10

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/heavy-ducks-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@protocolink/api': patch
---

add OpenOcean v2 test
76 changes: 76 additions & 0 deletions packages/api/examples/openocean-v2/swap-token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import * as api from '@protocolink/api';

// interface SwapTokenParams {
// input: {
// token: {
// chainId: number;
// address: string;
// decimals: number;
// symbol: string;
// name: string;
// };
// amount: string;
// };
// tokenOut: {
// chainId: number;
// address: string;
// decimals: number;
// symbol: string;
// name: string;
// };
// slippage?: number;
// disabledDexIds?: string;
// }

// interface SwapTokenFields {
// input: {
// token: {
// chainId: number;
// address: string;
// decimals: number;
// symbol: string;
// name: string;
// };
// amount: string;
// };
// output: {
// token: {
// chainId: number;
// address: string;
// decimals: number;
// symbol: string;
// name: string;
// };
// amount: string;
// };
// slippage?: number;
// disabledDexIds?: string;
// }

// interface SwapTokenLogic {
// rid: string;
// fields: SwapTokenFields;
// }

(async () => {
const chainId = 1088;

const tokenList = await api.protocols.openoceanv2.getSwapTokenTokenList(chainId);
const tokenIn = tokenList[0];
const tokenOut = tokenList[2];
console.log('tokenIn :>> ', JSON.stringify(tokenIn, null, 2));
console.log('tokenOut :>> ', JSON.stringify(tokenOut, null, 2));

const swapTokenQuotation = await api.protocols.openoceanv2.getSwapTokenQuotation(chainId, {
input: {
token: tokenIn,
amount: '10',
},
tokenOut,
slippage: 100,
});
console.log('swapTokenQuotation :>> ', JSON.stringify(swapTokenQuotation, null, 2));

const swapTokenLogic = await api.protocols.openoceanv2.newSwapTokenLogic(swapTokenQuotation);
console.log('swapTokenLogic :>> ', JSON.stringify(swapTokenLogic, null, 2));
})();
42 changes: 42 additions & 0 deletions packages/api/src/protocols/openocean-v2/swap-token.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { SwapTokenParams, getSwapTokenQuotation, getSwapTokenTokenList } from './swap-token';
import * as common from '@protocolink/common';
import { expect } from 'chai';
import * as logics from '@protocolink/logics';
import { metisTokens } from '@protocolink/test-helpers';

describe('OpenOceanV2 SwapTokenLogic', function () {
context('Test getTokenList', async function () {
logics.openoceanv2.SwapTokenLogic.supportedChainIds.forEach((chainId) => {
it(`network: ${common.toNetworkId(chainId)}`, async function () {
const tokenList = await getSwapTokenTokenList(chainId);
expect(tokenList).to.have.lengthOf.above(0);
});
});
});

context('Test getQuotation', async function () {
const chainId = common.ChainId.metis;

const testCases: SwapTokenParams[] = [
{
input: { token: metisTokens.METIS, amount: '1' },
tokenOut: metisTokens.USDC,
},
{
input: { token: metisTokens.USDC, amount: '1' },
tokenOut: metisTokens.METIS,
},
{
input: { token: metisTokens.USDC, amount: '1' },
tokenOut: metisTokens.DAI,
},
];

testCases.forEach((params, i) => {
it(`case ${i + 1}`, async function () {
const quotation = await getSwapTokenQuotation(chainId, params);
expect(quotation).to.include.all.keys('input', 'output');
});
});
});
});
Loading