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 IOLEND & Wagmi test and example #88

Merged
merged 2 commits into from
Sep 18, 2024
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/odd-timers-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@protocolink/api': patch
---

add Wagmi test and example
5 changes: 5 additions & 0 deletions .changeset/tough-icons-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@protocolink/api': patch
---

add IOLEND test and example
38 changes: 38 additions & 0 deletions packages/api/examples/iolend/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.iolend.InterestRateMode;
// output: {
// token: {
// chainId: number;
// address: string;
// decimals: number;
// symbol: string;
// name: string;
// };
// amount: string;
// };
// }

// interface BorrowLogic {
// rid: string;
// fields: BorrowFields;
// }

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

const tokenList = await api.protocols.iolend.getBorrowTokenList(chainId);
const underlyingToken = tokenList[0];
console.log('underlyingToken :>> ', JSON.stringify(underlyingToken, null, 2));

const borrowLogic = await api.protocols.iolend.newBorrowLogic({
interestRateMode: logics.iolend.InterestRateMode.variable,
output: {
token: underlyingToken,
amount: '10',
},
});
console.log('borrowLogic :>> ', JSON.stringify(borrowLogic, null, 2));
})();
71 changes: 71 additions & 0 deletions packages/api/examples/iolend/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 = 8822;

const tokenList = await api.protocols.iolend.getDepositTokenList(chainId);
const underlyingToken = tokenList[0][0];
const aToken = tokenList[0][1];
console.log('underlyingToken :>> ', JSON.stringify(underlyingToken, null, 2));
console.log('aToken :>> ', JSON.stringify(aToken, null, 2));

const depositQuotation = await api.protocols.iolend.getDepositQuotation(chainId, {
input: {
token: underlyingToken,
amount: '10',
},
tokenOut: aToken,
});
console.log('depositQuotation :>> ', JSON.stringify(depositQuotation, null, 2));

const depositLogic = await api.protocols.iolend.newDepositLogic(depositQuotation);
console.log('depositLogic :>> ', JSON.stringify(depositLogic, null, 2));
})();
53 changes: 53 additions & 0 deletions packages/api/examples/iolend/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.iolend.InterestRateMode;
// }

// interface RepayFields {
// input: {
// token: {
// chainId: number;
// address: string;
// decimals: number;
// symbol: string;
// name: string;
// };
// amount: string;
// };
// borrower: string;
// interestRateMode: logics.iolend.InterestRateMode;
// }

// interface RepayLogic {
// rid: string;
// fields: RepayFields;
// }

(async () => {
const chainId = 8822;
const account = '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa';

const tokenList = await api.protocols.iolend.getRepayTokenList(chainId);
const underlyingToken = tokenList[0];
console.log('underlyingToken :>> ', JSON.stringify(underlyingToken, null, 2));

const repayQuotation = await api.protocols.iolend.getRepayQuotation(chainId, {
borrower: account,
tokenIn: underlyingToken,
interestRateMode: logics.iolend.InterestRateMode.variable,
});
console.log('repayQuotation :>> ', JSON.stringify(repayQuotation, null, 2));

const repayLogic = await api.protocols.iolend.newRepayLogic(repayQuotation);
console.log('repayLogic :>> ', JSON.stringify(repayLogic, null, 2));
})();
71 changes: 71 additions & 0 deletions packages/api/examples/iolend/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 = 8822;

const tokenList = await api.protocols.iolend.getWithdrawTokenList(chainId);
const aToken = tokenList[0][0];
const underlyingToken = tokenList[0][1];
console.log('aToken :>> ', JSON.stringify(aToken, null, 2));
console.log('underlyingToken :>> ', JSON.stringify(underlyingToken, null, 2));

const withdrawQuotation = await api.protocols.iolend.getWithdrawQuotation(chainId, {
input: {
token: aToken,
amount: '10',
},
tokenOut: underlyingToken,
});
console.log('withdrawQuotation :>> ', JSON.stringify(withdrawQuotation, null, 2));

const withdrawLogic = await api.protocols.iolend.newWithdrawLogic(withdrawQuotation);
console.log('withdrawLogic :>> ', JSON.stringify(withdrawLogic, null, 2));
})();
100 changes: 100 additions & 0 deletions packages/api/examples/wagmi/swap-token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import * as api from '@protocolink/api';

// type 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;
// }
// | {
// tokenIn: {
// chainId: number;
// address: string;
// decimals: number;
// symbol: string;
// name: string;
// };
// output: {
// token: {
// chainId: number;
// address: string;
// decimals: number;
// symbol: string;
// name: string;
// };
// amount: string;
// };
// slippage?: number;
// };

// import * as core from '@protocolink/core';

// interface SwapTokenFields {
// tradeType: core.TradeType;
// 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;
// };
// fee?: number;
// path?: string;
// slippage?: number;
// }

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

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

const tokenList = await api.protocols.wagmi.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.wagmi.getSwapTokenQuotation(chainId, {
input: {
token: tokenIn,
amount: '10',
},
tokenOut,
slippage: 100,
});
console.log('swapTokenQuotation :>> ', JSON.stringify(swapTokenQuotation, null, 2));

const swapTokenLogic = await api.protocols.wagmi.newSwapTokenLogic(swapTokenQuotation);
console.log('swapTokenLogic :>> ', JSON.stringify(swapTokenLogic, null, 2));
})();
15 changes: 15 additions & 0 deletions packages/api/src/protocols/iolend/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('Iolend BorrowLogic', function () {
context('Test getTokenList', async function () {
logics.iolend.BorrowLogic.supportedChainIds.forEach((chainId) => {
it(`network: ${common.toNetworkId(chainId)}`, async function () {
const tokenList = await getBorrowTokenList(chainId);
expect(tokenList).to.have.lengthOf.above(0);
});
});
});
});
Loading
Loading