diff --git a/packages/api/examples/utility/custom-data.ts b/packages/api/examples/utility/custom-data.ts index 55be9ce0..d03e5c63 100644 --- a/packages/api/examples/utility/custom-data.ts +++ b/packages/api/examples/utility/custom-data.ts @@ -32,45 +32,46 @@ import * as common from '@protocolink/common'; // fields: CustomDataFields; // } -(async () => { - const chainId = 1; - const account = '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa'; +// TODO: unskip this after we set up 1inch API v5.2 (The public Swap API api.1inch.io is deprecated.) +// (async () => { +// const chainId = 1; +// const account = '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa'; - // 1. get quotation from 1inch api - const fromToken = { - chainId: 1, - address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', - decimals: 6, - symbol: 'USDC', - name: 'USD Coin', - }; - const toToken = { - chainId: 1, - address: '0x6B175474E89094C44Da98b954EedeAC495271d0F', - decimals: 18, - symbol: 'DAI', - name: 'Dai Stablecoin', - }; - const input = new common.TokenAmount(fromToken, '100'); +// // 1. get quotation from 1inch api +// const fromToken = { +// chainId: 1, +// address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', +// decimals: 6, +// symbol: 'USDC', +// name: 'USD Coin', +// }; +// const toToken = { +// chainId: 1, +// address: '0x6B175474E89094C44Da98b954EedeAC495271d0F', +// decimals: 18, +// symbol: 'DAI', +// name: 'Dai Stablecoin', +// }; +// const input = new common.TokenAmount(fromToken, '100'); - const { data } = await axios.get(`https://api.1inch.io/v5.0/${chainId}/swap`, { - params: { - fromTokenAddress: fromToken.address, - toTokenAddress: toToken.address, - amount: input.amountWei.toString(), - fromAddress: account, - slippage: 1, - disableEstimate: true, - }, - }); - console.log('data :>> ', JSON.stringify(data)); - const output = new common.TokenAmount(toToken).setWei(data.toTokenAmount); +// const { data } = await axios.get(`https://api.1inch.io/v5.0/${chainId}/swap`, { +// params: { +// fromTokenAddress: fromToken.address, +// toTokenAddress: toToken.address, +// amount: input.amountWei.toString(), +// fromAddress: account, +// slippage: 1, +// disableEstimate: true, +// }, +// }); +// console.log('data :>> ', JSON.stringify(data)); +// const output = new common.TokenAmount(toToken).setWei(data.toTokenAmount); - const customDataLogic = await api.protocols.utility.newCustomDataLogic({ - inputs: [input], - outputs: [output], - to: data.tx.to, - data: data.tx.data, - }); - console.log('customDataLogic :>> ', JSON.stringify(customDataLogic, null, 2)); -})(); +// const customDataLogic = await api.protocols.utility.newCustomDataLogic({ +// inputs: [input], +// outputs: [output], +// to: data.tx.to, +// data: data.tx.data, +// }); +// console.log('customDataLogic :>> ', JSON.stringify(customDataLogic, null, 2)); +// })(); diff --git a/packages/api/package.json b/packages/api/package.json index fba35452..57e67b6c 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -28,7 +28,7 @@ "dependencies": { "@protocolink/common": "^0.3.0", "@protocolink/core": "^0.4.0", - "@protocolink/logics": "^0.4.0", + "@protocolink/logics": "^0.4.1", "@types/lodash": "^4.14.195", "@types/uuid": "^9.0.2", "@uniswap/permit2-sdk": "^1.2.0", diff --git a/packages/api/src/protocols/index.ts b/packages/api/src/protocols/index.ts index 5be86908..3326a546 100644 --- a/packages/api/src/protocols/index.ts +++ b/packages/api/src/protocols/index.ts @@ -3,6 +3,7 @@ export * as aavev3 from './aave-v3'; export * as balancerv2 from './balancer-v2'; export * as compoundv3 from './compound-v3'; export * as paraswapv5 from './paraswap-v5'; +export * as radiantv2 from './radiant-v2'; export * as syncswap from './syncswap'; export * as uniswapv3 from './uniswap-v3'; export * as utility from './utility'; diff --git a/packages/api/src/protocols/radiant-v2/borrow.ts b/packages/api/src/protocols/radiant-v2/borrow.ts new file mode 100644 index 00000000..bb3ec651 --- /dev/null +++ b/packages/api/src/protocols/radiant-v2/borrow.ts @@ -0,0 +1,16 @@ +import { Logic } from 'src/types'; +import * as common from '@protocolink/common'; +import { getProtocolTokenList } from 'src/api'; +import * as logics from '@protocolink/logics'; + +export type BorrowFields = common.Declasifying; + +export type BorrowLogic = Logic; + +export async function getBorrowTokenList(chainId: number): Promise { + return getProtocolTokenList(chainId, logics.radiantv2.BorrowLogic.rid); +} + +export function newBorrowLogic(fields: BorrowFields): BorrowLogic { + return { rid: logics.radiantv2.BorrowLogic.rid, fields }; +} diff --git a/packages/api/src/protocols/radiant-v2/deposit.ts b/packages/api/src/protocols/radiant-v2/deposit.ts new file mode 100644 index 00000000..69aa0e60 --- /dev/null +++ b/packages/api/src/protocols/radiant-v2/deposit.ts @@ -0,0 +1,25 @@ +import { Logic } from 'src/types'; +import * as common from '@protocolink/common'; +import { getProtocolTokenList, quote } from 'src/api'; +import * as logics from '@protocolink/logics'; + +export type DepositParams = common.Declasifying; + +export type DepositFields = common.Declasifying; + +export type DepositLogic = Logic; + +export async function getDepositTokenList(chainId: number): Promise { + return getProtocolTokenList(chainId, logics.radiantv2.DepositLogic.rid); +} + +export async function getDepositQuotation( + chainId: number, + params: DepositParams +): Promise { + return quote(chainId, logics.radiantv2.DepositLogic.rid, params); +} + +export function newDepositLogic(fields: DepositFields): DepositLogic { + return { rid: logics.radiantv2.DepositLogic.rid, fields }; +} diff --git a/packages/api/src/protocols/radiant-v2/flash-loan.ts b/packages/api/src/protocols/radiant-v2/flash-loan.ts new file mode 100644 index 00000000..5f9fa5a9 --- /dev/null +++ b/packages/api/src/protocols/radiant-v2/flash-loan.ts @@ -0,0 +1,27 @@ +import { FlashLoanFields, FlashLoanLogic } from 'src/types'; +import * as common from '@protocolink/common'; +import { getProtocolTokenList, quote } from 'src/api'; +import * as logics from '@protocolink/logics'; +import { v4 as uuid } from 'uuid'; + +export type FlashLoanParams = common.Declasifying; + +export async function getFlashLoanTokenList(chainId: number): Promise { + return getProtocolTokenList(chainId, logics.radiantv2.FlashLoanLogic.rid); +} + +export async function getFlashLoanQuotation( + chainId: number, + params: FlashLoanParams +): Promise { + return quote(chainId, logics.radiantv2.FlashLoanLogic.rid, params); +} + +export function newFlashLoanLogic(fields: FlashLoanFields): FlashLoanLogic { + return { rid: logics.radiantv2.FlashLoanLogic.rid, fields }; +} + +export function newFlashLoanLogicPair(loans: FlashLoanFields['loans']): [FlashLoanLogic, FlashLoanLogic] { + const id = uuid(); + return [newFlashLoanLogic({ id, loans, isLoan: true }), newFlashLoanLogic({ id, loans, isLoan: false })]; +} diff --git a/packages/api/src/protocols/radiant-v2/index.ts b/packages/api/src/protocols/radiant-v2/index.ts new file mode 100644 index 00000000..95be47c4 --- /dev/null +++ b/packages/api/src/protocols/radiant-v2/index.ts @@ -0,0 +1,5 @@ +export * from './borrow'; +export * from './deposit'; +export * from './flash-loan'; +export * from './repay'; +export * from './withdraw'; diff --git a/packages/api/src/protocols/radiant-v2/repay.ts b/packages/api/src/protocols/radiant-v2/repay.ts new file mode 100644 index 00000000..d46e4595 --- /dev/null +++ b/packages/api/src/protocols/radiant-v2/repay.ts @@ -0,0 +1,25 @@ +import { Logic } from 'src/types'; +import * as common from '@protocolink/common'; +import { getProtocolTokenList, quote } from 'src/api'; +import * as logics from '@protocolink/logics'; + +export type RepayParams = common.Declasifying; + +export type RepayFields = common.Declasifying; + +export type RepayLogic = Logic; + +export async function getRepayTokenList(chainId: number): Promise { + return getProtocolTokenList(chainId, logics.radiantv2.RepayLogic.rid); +} + +export async function getRepayQuotation( + chainId: number, + params: RepayParams +): Promise { + return quote(chainId, logics.radiantv2.RepayLogic.rid, params); +} + +export function newRepayLogic(fields: RepayFields): RepayLogic { + return { rid: logics.radiantv2.RepayLogic.rid, fields }; +} diff --git a/packages/api/src/protocols/radiant-v2/withdraw.ts b/packages/api/src/protocols/radiant-v2/withdraw.ts new file mode 100644 index 00000000..88e69469 --- /dev/null +++ b/packages/api/src/protocols/radiant-v2/withdraw.ts @@ -0,0 +1,25 @@ +import { Logic } from 'src/types'; +import * as common from '@protocolink/common'; +import { getProtocolTokenList, quote } from 'src/api'; +import * as logics from '@protocolink/logics'; + +export type WithdrawParams = common.Declasifying; + +export type WithdrawFields = common.Declasifying; + +export type WithdrawLogic = Logic; + +export async function getWithdrawTokenList(chainId: number): Promise { + return getProtocolTokenList(chainId, logics.radiantv2.WithdrawLogic.rid); +} + +export async function getWithdrawQuotation( + chainId: number, + params: WithdrawParams +): Promise { + return quote(chainId, logics.radiantv2.WithdrawLogic.rid, params); +} + +export function newWithdrawLogic(fields: WithdrawFields): WithdrawLogic { + return { rid: logics.radiantv2.WithdrawLogic.rid, fields }; +} diff --git a/yarn.lock b/yarn.lock index 57eaae91..79c37db2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1080,10 +1080,10 @@ node-addon-api "^3.2.1" node-gyp-build "^4.3.0" -"@protocolink/logics@^0.4.0": - version "0.4.0" - resolved "https://registry.yarnpkg.com/@protocolink/logics/-/logics-0.4.0.tgz#a58c685daf64c0279d005e45673ae2e246f0c01f" - integrity sha512-k79ztS1nNtQXv5+KzUFeVQkqYoPMPMU7o147mEb43jVPd+jgzv3OGuZsLfAGD8+QGD4Kx72ecDKH5yTXA9TK2A== +"@protocolink/logics@^0.4.1": + version "0.4.1" + resolved "https://registry.yarnpkg.com/@protocolink/logics/-/logics-0.4.1.tgz#cdc9f7e2b7c4fba66c260231d447cc58b5984cd6" + integrity sha512-RQf8sYWuefsxU5Nk/euFASR3UTa61IMqKllRZZSk+9L1/megh4swnyFWyBbx13XjAe3wcaXF5SGjzlNVp4EZfQ== dependencies: "@paraswap/sdk" "^6.2.2" "@protocolink/common" "^0.3.0"