-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from Jeff-CCH/feat/integrate-open-ocean
Add OpenOcean v2 test
- Loading branch information
Showing
3 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@protocolink/api': patch | ||
--- | ||
|
||
add OpenOcean v2 test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
42
packages/api/src/protocols/openocean-v2/swap-token.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); | ||
}); | ||
}); |