-
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 #3 from LuPoYi/feature/add_radiant_v2_test_20230928
feat: add radiant v2 test
- Loading branch information
Showing
11 changed files
with
469 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 radiant 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,38 @@ | ||
import * as api from '@protocolink/api'; | ||
import * as logics from '@protocolink/logics'; | ||
|
||
// interface BorrowFields { | ||
// interestRateMode: logics.radiantv2.InterestRateMode; | ||
// output: { | ||
// token: { | ||
// chainId: number; | ||
// address: string; | ||
// decimals: number; | ||
// symbol: string; | ||
// name: string; | ||
// }; | ||
// amount: string; | ||
// }; | ||
// } | ||
|
||
// interface BorrowLogic { | ||
// rid: string; | ||
// fields: BorrowFields; | ||
// } | ||
|
||
(async () => { | ||
const chainId = 42161; | ||
|
||
const tokenList = await api.protocols.radiantv2.getBorrowTokenList(chainId); | ||
const underlyingToken = tokenList[0]; | ||
console.log('underlyingToken :>> ', JSON.stringify(underlyingToken, null, 2)); | ||
|
||
const borrowLogic = await api.protocols.radiantv2.newBorrowLogic({ | ||
interestRateMode: logics.radiantv2.InterestRateMode.variable, | ||
output: { | ||
token: underlyingToken, | ||
amount: '10', | ||
}, | ||
}); | ||
console.log('borrowLogic :>> ', JSON.stringify(borrowLogic, null, 2)); | ||
})(); |
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,71 @@ | ||
import * as api from '@protocolink/api'; | ||
|
||
// interface DepositParams { | ||
// 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; | ||
// }; | ||
// } | ||
|
||
// interface DepositFields { | ||
// 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; | ||
// }; | ||
// } | ||
|
||
// interface DepositLogic { | ||
// rid: string; | ||
// fields: DepositFields; | ||
// } | ||
|
||
(async () => { | ||
const chainId = 42161; | ||
|
||
const tokenList = await api.protocols.radiantv2.getDepositTokenList(chainId); | ||
const underlyingToken = tokenList[0][0]; | ||
const rToken = tokenList[0][1]; | ||
console.log('underlyingToken :>> ', JSON.stringify(underlyingToken, null, 2)); | ||
console.log('rToken :>> ', JSON.stringify(rToken, null, 2)); | ||
|
||
const depositQuotation = await api.protocols.radiantv2.getDepositQuotation(chainId, { | ||
input: { | ||
token: underlyingToken, | ||
amount: '10', | ||
}, | ||
tokenOut: rToken, | ||
}); | ||
console.log('depositQuotation :>> ', JSON.stringify(depositQuotation, null, 2)); | ||
|
||
const depositLogic = await api.protocols.radiantv2.newDepositLogic(depositQuotation); | ||
console.log('depositLogic :>> ', JSON.stringify(depositLogic, null, 2)); | ||
})(); |
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,50 @@ | ||
import * as api from '@protocolink/api'; | ||
|
||
// import * as common from '@protocolink/common'; | ||
|
||
// interface FlashLoanLogicFields { | ||
// id: string; | ||
// outputs: common.TokenAmounts; | ||
// isLoan: boolean; | ||
// } | ||
|
||
// interface FlashLoanFields { | ||
// id: string; | ||
// outputs: { | ||
// token: { | ||
// chainId: number; | ||
// address: string; | ||
// decimals: number; | ||
// symbol: string; | ||
// name: string; | ||
// }; | ||
// amount: string; | ||
// }[]; | ||
// isLoan: boolean; | ||
// } | ||
|
||
// interface FlashLoanLogic { | ||
// rid: string; | ||
// fields: FlashLoanFields; | ||
// } | ||
|
||
(async () => { | ||
const chainId = 42161; | ||
|
||
const tokenList = await api.protocols.radiantv2.getFlashLoanTokenList(chainId); | ||
const underlyingToken = tokenList[0]; | ||
console.log('underlyingToken :>> ', JSON.stringify(underlyingToken, null, 2)); | ||
|
||
const outputs = [ | ||
{ | ||
token: underlyingToken, | ||
amount: '10000', | ||
}, | ||
]; | ||
|
||
const [flashLoanLoanLogic, flashLoanRepayLogic] = api.protocols.radiantv2.newFlashLoanLogicPair(outputs); | ||
const logics = [flashLoanLoanLogic]; | ||
|
||
logics.push(flashLoanRepayLogic); | ||
console.log('logics :>> ', JSON.stringify(logics, null, 2)); | ||
})(); |
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,53 @@ | ||
import * as api from '@protocolink/api'; | ||
import * as logics from '@protocolink/logics'; | ||
|
||
// interface RepayParams { | ||
// tokenIn: { | ||
// chainId: number; | ||
// address: string; | ||
// decimals: number; | ||
// symbol: string; | ||
// name: string; | ||
// }; | ||
// borrower: string; | ||
// interestRateMode: logics.radiantv2.InterestRateMode; | ||
// } | ||
|
||
// interface RepayFields { | ||
// input: { | ||
// token: { | ||
// chainId: number; | ||
// address: string; | ||
// decimals: number; | ||
// symbol: string; | ||
// name: string; | ||
// }; | ||
// amount: string; | ||
// }; | ||
// borrower: string; | ||
// interestRateMode: logics.radiantv2.InterestRateMode; | ||
// } | ||
|
||
// interface RepayLogic { | ||
// rid: string; | ||
// fields: RepayFields; | ||
// } | ||
|
||
(async () => { | ||
const chainId = 42161; | ||
const account = '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa'; | ||
|
||
const tokenList = await api.protocols.radiantv2.getRepayTokenList(chainId); | ||
const underlyingToken = tokenList[0]; | ||
console.log('underlyingToken :>> ', JSON.stringify(underlyingToken, null, 2)); | ||
|
||
const repayQuotation = await api.protocols.radiantv2.getRepayQuotation(chainId, { | ||
borrower: account, | ||
tokenIn: underlyingToken, | ||
interestRateMode: logics.radiantv2.InterestRateMode.variable, | ||
}); | ||
console.log('repayQuotation :>> ', JSON.stringify(repayQuotation, null, 2)); | ||
|
||
const repayLogic = await api.protocols.radiantv2.newRepayLogic(repayQuotation); | ||
console.log('repayLogic :>> ', JSON.stringify(repayLogic, null, 2)); | ||
})(); |
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,71 @@ | ||
import * as api from '@protocolink/api'; | ||
|
||
// interface WithdrawParams { | ||
// 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; | ||
// }; | ||
// } | ||
|
||
// interface WithdrawFields { | ||
// 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; | ||
// }; | ||
// } | ||
|
||
// interface WithdrawLogic { | ||
// rid: string; | ||
// fields: WithdrawFields; | ||
// } | ||
|
||
(async () => { | ||
const chainId = 42161; | ||
|
||
const tokenList = await api.protocols.radiantv2.getWithdrawTokenList(chainId); | ||
const rToken = tokenList[0][0]; | ||
const underlyingToken = tokenList[0][1]; | ||
console.log('rToken :>> ', JSON.stringify(rToken, null, 2)); | ||
console.log('underlyingToken :>> ', JSON.stringify(underlyingToken, null, 2)); | ||
|
||
const withdrawQuotation = await api.protocols.radiantv2.getWithdrawQuotation(chainId, { | ||
input: { | ||
token: rToken, | ||
amount: '10', | ||
}, | ||
tokenOut: underlyingToken, | ||
}); | ||
console.log('withdrawQuotation :>> ', JSON.stringify(withdrawQuotation, null, 2)); | ||
|
||
const withdrawLogic = await api.protocols.radiantv2.newWithdrawLogic(withdrawQuotation); | ||
console.log('withdrawLogic :>> ', JSON.stringify(withdrawLogic, null, 2)); | ||
})(); |
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,15 @@ | ||
import * as common from '@protocolink/common'; | ||
import { expect } from 'chai'; | ||
import { getBorrowTokenList } from './borrow'; | ||
import * as logics from '@protocolink/logics'; | ||
|
||
describe('RadiantV2 BorrowLogic', function () { | ||
context('Test getTokenList', async function () { | ||
logics.radiantv2.BorrowLogic.supportedChainIds.forEach((chainId) => { | ||
it(`network: ${common.toNetworkId(chainId)}`, async function () { | ||
const tokenList = await getBorrowTokenList(chainId); | ||
expect(tokenList).to.have.lengthOf.above(0); | ||
}); | ||
}); | ||
}); | ||
}); |
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,37 @@ | ||
import { DepositParams, getDepositQuotation, getDepositTokenList } from './deposit'; | ||
import * as common from '@protocolink/common'; | ||
import { expect } from 'chai'; | ||
import * as logics from '@protocolink/logics'; | ||
|
||
describe('RadiantV2 DepositLogic', function () { | ||
context('Test getTokenList', async function () { | ||
logics.radiantv2.DepositLogic.supportedChainIds.forEach((chainId) => { | ||
it(`network: ${common.toNetworkId(chainId)}`, async function () { | ||
const tokenList = await getDepositTokenList(chainId); | ||
expect(tokenList).to.have.lengthOf.above(0); | ||
}); | ||
}); | ||
}); | ||
|
||
context('Test getQuotation', async function () { | ||
const chainId = common.ChainId.arbitrum; | ||
|
||
const testCases: DepositParams[] = [ | ||
{ | ||
input: { token: logics.radiantv2.arbitrumTokens.ETH, amount: '1' }, | ||
tokenOut: logics.radiantv2.arbitrumTokens.rWETH, | ||
}, | ||
{ | ||
input: { token: logics.radiantv2.arbitrumTokens.USDC, amount: '1' }, | ||
tokenOut: logics.radiantv2.arbitrumTokens.rUSDC, | ||
}, | ||
]; | ||
|
||
testCases.forEach((params, i) => { | ||
it(`case ${i + 1}`, async function () { | ||
const quotation = await getDepositQuotation(chainId, params); | ||
expect(quotation).to.include.all.keys('input', 'output'); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.