Skip to content

Commit

Permalink
Merge pull request #3 from LuPoYi/feature/add_radiant_v2_test_20230928
Browse files Browse the repository at this point in the history
feat: add radiant v2 test
  • Loading branch information
LuPoYi authored Oct 2, 2023
2 parents 87fe5b6 + 6c0b2f1 commit 55d7b27
Show file tree
Hide file tree
Showing 11 changed files with 469 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/six-singers-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@protocolink/api': patch
---

add radiant v2 test
38 changes: 38 additions & 0 deletions packages/api/examples/radiant-v2/borrow.ts
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));
})();
71 changes: 71 additions & 0 deletions packages/api/examples/radiant-v2/deposit.ts
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));
})();
50 changes: 50 additions & 0 deletions packages/api/examples/radiant-v2/flash-loan.ts
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));
})();
53 changes: 53 additions & 0 deletions packages/api/examples/radiant-v2/repay.ts
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));
})();
71 changes: 71 additions & 0 deletions packages/api/examples/radiant-v2/withdraw.ts
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));
})();
15 changes: 15 additions & 0 deletions packages/api/src/protocols/radiant-v2/borrow.test.ts
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);
});
});
});
});
37 changes: 37 additions & 0 deletions packages/api/src/protocols/radiant-v2/deposit.test.ts
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');
});
});
});
});
Loading

0 comments on commit 55d7b27

Please sign in to comment.