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 Spark Test & Permit2 Test #16

Merged
merged 2 commits into from
Nov 29, 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/plenty-cooks-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@protocolink/api': patch
---

add Spark test
5 changes: 5 additions & 0 deletions .changeset/sour-terms-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@protocolink/api': patch
---

add Permit2 test
36 changes: 36 additions & 0 deletions packages/api/examples/permit2/pull-token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as api from '@protocolink/api';

// interface PullTokenFields {
// input: {
// token: {
// chainId: number;
// address: string;
// decimals: number;
// symbol: string;
// name: string;
// };
// amount: string;
// };
// }

// interface PullTokenLogic {
// rid: string;
// fields: PullTokenFields;
// }

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

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

const pullTokenLogic = await api.protocols.permit2.newPullTokenLogic({
input: {
token: tokenIn,
amount: '10',
},
});

console.log('pullTokenLogic :>> ', JSON.stringify(pullTokenLogic, null, 2));
})();
38 changes: 38 additions & 0 deletions packages/api/examples/spark/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.spark.InterestRateMode;
// output: {
// token: {
// chainId: number;
// address: string;
// decimals: number;
// symbol: string;
// name: string;
// };
// amount: string;
// };
// }

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

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

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

const borrowLogic = await api.protocols.spark.newBorrowLogic({
interestRateMode: logics.spark.InterestRateMode.variable,
output: {
token: underlyingToken,
amount: '10',
},
});
console.log('borrowLogic :>> ', JSON.stringify(borrowLogic, null, 2));
})();
52 changes: 52 additions & 0 deletions packages/api/examples/spark/flash-loan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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 = 1;

const tokenList = await api.protocols.spark.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.spark.newFlashLoanLogicPair(outputs);
const logics = [flashLoanLoanLogic];
// logics.push(swapLogic)
// logics.push(supplyLogic)
// logics.push(...)
logics.push(flashLoanRepayLogic);
console.log('logics :>> ', JSON.stringify(logics, null, 2));
})();
53 changes: 53 additions & 0 deletions packages/api/examples/spark/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.spark.InterestRateMode;
// }

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

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

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

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

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

const repayLogic = await api.protocols.spark.newRepayLogic(repayQuotation);
console.log('repayLogic :>> ', JSON.stringify(repayLogic, null, 2));
})();
71 changes: 71 additions & 0 deletions packages/api/examples/spark/supply.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import * as api from '@protocolink/api';

// interface SupplyParams {
// 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 SupplyFields {
// 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 SupplyLogic {
// rid: string;
// fields: SupplyFields;
// }

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

const tokenList = await api.protocols.spark.getSupplyTokenList(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 supplyQuotation = await api.protocols.spark.getSupplyQuotation(chainId, {
input: {
token: underlyingToken,
amount: '10',
},
tokenOut: aToken,
});
console.log('supplyQuotation :>> ', JSON.stringify(supplyQuotation, null, 2));

const supplyLogic = await api.protocols.spark.newSupplyLogic(supplyQuotation);
console.log('supplyLogic :>> ', JSON.stringify(supplyLogic, null, 2));
})();
71 changes: 71 additions & 0 deletions packages/api/examples/spark/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 = 1;

const tokenList = await api.protocols.spark.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.spark.getWithdrawQuotation(chainId, {
input: {
token: aToken,
amount: '10',
},
tokenOut: underlyingToken,
});
console.log('withdrawQuotation :>> ', JSON.stringify(withdrawQuotation, null, 2));

const withdrawLogic = await api.protocols.spark.newWithdrawLogic(withdrawQuotation);
console.log('withdrawLogic :>> ', JSON.stringify(withdrawLogic, null, 2));
})();
15 changes: 15 additions & 0 deletions packages/api/src/protocols/permit2/pull-token.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 { getPullTokenTokenList } from './pull-token';
import * as logics from '@protocolink/logics';

describe('Permit2 PullTokenLogic', function () {
context('Test getTokenList', async function () {
logics.permit2.PullTokenLogic.supportedChainIds.forEach((chainId) => {
it(`network: ${common.toNetworkId(chainId)}`, async function () {
const tokenList = await getPullTokenTokenList(chainId);
expect(tokenList).to.have.lengthOf.above(0);
});
});
});
});
15 changes: 15 additions & 0 deletions packages/api/src/protocols/spark/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('Spark BorrowLogic', function () {
context('Test getTokenList', async function () {
logics.spark.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