├── .changeset ├── README.md └── config.json ├── .eslintignore ├── .eslintrc.js ├── .github └── workflows │ ├── e2e-test.yml │ ├── lint.yml │ └── unit-test.yml ├── .gitignore ├── .mocharc.js ├── .prettierignore ├── .prettierrc ├── LICENSE ├── README.md ├── hardhat.config.ts ├── package.json ├── packages ├── api │ ├── CHANGELOG.md │ ├── README.md │ ├── examples │ │ ├── aave-v2 │ │ │ ├── borrow.ts │ │ │ ├── deposit.ts │ │ │ ├── flash-loan.ts │ │ │ ├── repay.ts │ │ │ └── withdraw.ts │ │ ├── aave-v3 │ │ │ ├── borrow.ts │ │ │ ├── flash-loan.ts │ │ │ ├── repay.ts │ │ │ ├── supply.ts │ │ │ └── withdraw.ts │ │ ├── balancer-v2 │ │ │ └── flash-loan.ts │ │ ├── compound-v3 │ │ │ ├── borrow.ts │ │ │ ├── claim.ts │ │ │ ├── repay.ts │ │ │ ├── supply-base.ts │ │ │ ├── supply-collateral.ts │ │ │ ├── withdraw-base.ts │ │ │ └── withdraw-collateral.ts │ │ ├── iolend │ │ │ ├── borrow.ts │ │ │ ├── deposit.ts │ │ │ ├── repay.ts │ │ │ └── withdraw.ts │ │ ├── magicsea │ │ │ └── swap-token.ts │ │ ├── morphoblue │ │ │ ├── borrow.ts │ │ │ ├── flash-loan.ts │ │ │ ├── repay.ts │ │ │ ├── supply-collateral.ts │ │ │ ├── supply.ts │ │ │ ├── withdraw-collateral.ts │ │ │ └── withdraw.ts │ │ ├── openocean-v2 │ │ │ └── swap-token.ts │ │ ├── paraswap-v5 │ │ │ └── swap-token.ts │ │ ├── permit2 │ │ │ └── pull-token.ts │ │ ├── radiant-v2 │ │ │ ├── borrow.ts │ │ │ ├── deposit.ts │ │ │ ├── flash-loan.ts │ │ │ ├── repay.ts │ │ │ └── withdraw.ts │ │ ├── spark │ │ │ ├── borrow.ts │ │ │ ├── flash-loan.ts │ │ │ ├── repay.ts │ │ │ ├── supply.ts │ │ │ └── withdraw.ts │ │ ├── stargate-v2 │ │ │ └── swap-token.ts │ │ ├── stargate │ │ │ └── swap-token.ts │ │ ├── uniswap-v3-swap-and-aave-v3-supply.ts │ │ ├── uniswap-v3 │ │ │ └── swap-token.ts │ │ ├── utility │ │ │ ├── custom-data.ts │ │ │ ├── multi-send.ts │ │ │ ├── send-token.ts │ │ │ └── wrapped-native-token.ts │ │ ├── wagmi │ │ │ └── swap-token.ts │ │ └── zeroex-v4 │ │ │ └── swap-token.ts │ ├── package.json │ ├── src │ │ ├── api.test.ts │ │ ├── api.ts │ │ ├── index.ts │ │ ├── protocols │ │ │ ├── aave-v2 │ │ │ │ ├── borrow.test.ts │ │ │ │ ├── borrow.ts │ │ │ │ ├── deposit.test.ts │ │ │ │ ├── deposit.ts │ │ │ │ ├── flash-loan.test.ts │ │ │ │ ├── flash-loan.ts │ │ │ │ ├── index.ts │ │ │ │ ├── repay.test.ts │ │ │ │ ├── repay.ts │ │ │ │ ├── withdraw.test.ts │ │ │ │ └── withdraw.ts │ │ │ ├── aave-v3 │ │ │ │ ├── borrow.test.ts │ │ │ │ ├── borrow.ts │ │ │ │ ├── flash-loan.test.ts │ │ │ │ ├── flash-loan.ts │ │ │ │ ├── index.ts │ │ │ │ ├── repay.test.ts │ │ │ │ ├── repay.ts │ │ │ │ ├── supply.test.ts │ │ │ │ ├── supply.ts │ │ │ │ ├── withdraw.test.ts │ │ │ │ └── withdraw.ts │ │ │ ├── balancer-v2 │ │ │ │ ├── flash-loan.test.ts │ │ │ │ ├── flash-loan.ts │ │ │ │ └── index.ts │ │ │ ├── compound-v3 │ │ │ │ ├── borrow.test.ts │ │ │ │ ├── borrow.ts │ │ │ │ ├── claim.test.ts │ │ │ │ ├── claim.ts │ │ │ │ ├── index.ts │ │ │ │ ├── repay.test.ts │ │ │ │ ├── repay.ts │ │ │ │ ├── supply-base.test.ts │ │ │ │ ├── supply-base.ts │ │ │ │ ├── supply-collateral.test.ts │ │ │ │ ├── supply-collateral.ts │ │ │ │ ├── withdraw-base.test.ts │ │ │ │ ├── withdraw-base.ts │ │ │ │ ├── withdraw-collateral.test.ts │ │ │ │ └── withdraw-collateral.ts │ │ │ ├── index.test.ts │ │ │ ├── index.ts │ │ │ ├── iolend │ │ │ │ ├── borrow.test.ts │ │ │ │ ├── borrow.ts │ │ │ │ ├── deposit.test.ts │ │ │ │ ├── deposit.ts │ │ │ │ ├── index.ts │ │ │ │ ├── repay.test.ts │ │ │ │ ├── repay.ts │ │ │ │ ├── withdraw.test.ts │ │ │ │ └── withdraw.ts │ │ │ ├── magicsea │ │ │ │ ├── index.ts │ │ │ │ ├── swap-token.test.ts │ │ │ │ └── swap-token.ts │ │ │ ├── morphoblue │ │ │ │ ├── borrow.test.ts │ │ │ │ ├── borrow.ts │ │ │ │ ├── flash-loan.test.ts │ │ │ │ ├── flash-loan.ts │ │ │ │ ├── index.ts │ │ │ │ ├── repay.test.ts │ │ │ │ ├── repay.ts │ │ │ │ ├── supply-collateral.test.ts │ │ │ │ ├── supply-collateral.ts │ │ │ │ ├── supply.test.ts │ │ │ │ ├── supply.ts │ │ │ │ ├── withdraw-collateral.test.ts │ │ │ │ ├── withdraw-collateral.ts │ │ │ │ ├── withdraw.test.ts │ │ │ │ └── withdraw.ts │ │ │ ├── openocean-v2 │ │ │ │ ├── index.ts │ │ │ │ ├── swap-token.test.ts │ │ │ │ └── swap-token.ts │ │ │ ├── paraswap-v5 │ │ │ │ ├── index.ts │ │ │ │ ├── swap-token.test.ts │ │ │ │ └── swap-token.ts │ │ │ ├── permit2 │ │ │ │ ├── index.ts │ │ │ │ ├── pull-token.test.ts │ │ │ │ └── pull-token.ts │ │ │ ├── radiant-v2 │ │ │ │ ├── borrow.test.ts │ │ │ │ ├── borrow.ts │ │ │ │ ├── deposit.test.ts │ │ │ │ ├── deposit.ts │ │ │ │ ├── flash-loan.test.ts │ │ │ │ ├── flash-loan.ts │ │ │ │ ├── index.ts │ │ │ │ ├── repay.test.ts │ │ │ │ ├── repay.ts │ │ │ │ ├── withdraw.test.ts │ │ │ │ └── withdraw.ts │ │ │ ├── sonne │ │ │ │ ├── borrow.ts │ │ │ │ ├── index.ts │ │ │ │ ├── repay.ts │ │ │ │ ├── supply.ts │ │ │ │ └── withdraw.ts │ │ │ ├── spark │ │ │ │ ├── borrow.test.ts │ │ │ │ ├── borrow.ts │ │ │ │ ├── flash-loan.test.ts │ │ │ │ ├── flash-loan.ts │ │ │ │ ├── index.ts │ │ │ │ ├── repay.test.ts │ │ │ │ ├── repay.ts │ │ │ │ ├── supply.test.ts │ │ │ │ ├── supply.ts │ │ │ │ ├── withdraw.test.ts │ │ │ │ └── withdraw.ts │ │ │ ├── stargate-v2 │ │ │ │ ├── index.ts │ │ │ │ ├── swap-token.test.ts │ │ │ │ └── swap-token.ts │ │ │ ├── stargate │ │ │ │ ├── index.ts │ │ │ │ ├── swap-token.test.ts │ │ │ │ └── swap-token.ts │ │ │ ├── syncswap │ │ │ │ ├── index.ts │ │ │ │ ├── swap-token.test.ts │ │ │ │ └── swap-token.ts │ │ │ ├── uniswap-v3 │ │ │ │ ├── index.ts │ │ │ │ ├── swap-token.test.ts │ │ │ │ └── swap-token.ts │ │ │ ├── utility │ │ │ │ ├── custom-data.ts │ │ │ │ ├── flash-loan-aggregator.test.ts │ │ │ │ ├── flash-loan-aggregator.ts │ │ │ │ ├── index.ts │ │ │ │ ├── multi-send.test.ts │ │ │ │ ├── multi-send.ts │ │ │ │ ├── send-token.test.ts │ │ │ │ ├── send-token.ts │ │ │ │ ├── wrapped-native-token.test.ts │ │ │ │ └── wrapped-native-token.ts │ │ │ ├── wagmi │ │ │ │ ├── index.ts │ │ │ │ ├── swap-token.test.ts │ │ │ │ └── swap-token.ts │ │ │ └── zeroex-v4 │ │ │ │ ├── index.ts │ │ │ │ ├── swap-token.test.ts │ │ │ │ └── swap-token.ts │ │ └── types.ts │ ├── tsconfig.build.json │ └── tsconfig.json ├── common │ ├── CHANGELOG.md │ ├── README.md │ ├── hardhat.config.ts │ ├── package.json │ ├── src │ │ ├── abis │ │ │ ├── ERC20.json │ │ │ ├── Multicall3.json │ │ │ └── WETH.json │ │ ├── constants.ts │ │ ├── contracts │ │ │ ├── ERC20.ts │ │ │ ├── Multicall3.ts │ │ │ ├── WETH.ts │ │ │ ├── common.ts │ │ │ ├── factories │ │ │ │ ├── ERC20__factory.ts │ │ │ │ ├── Multicall3__factory.ts │ │ │ │ ├── WETH__factory.ts │ │ │ │ └── index.ts │ │ │ └── index.ts │ │ ├── index.ts │ │ ├── networks │ │ │ ├── data.json │ │ │ ├── index.test.ts │ │ │ └── index.ts │ │ ├── tokens │ │ │ ├── constants.ts │ │ │ ├── data │ │ │ │ ├── arbitrum.json │ │ │ │ ├── avalanche.json │ │ │ │ ├── base.json │ │ │ │ ├── bnb.json │ │ │ │ ├── gnosis.json │ │ │ │ ├── iota.json │ │ │ │ ├── mainnet.json │ │ │ │ ├── metis.json │ │ │ │ ├── optimism.json │ │ │ │ ├── polygon.json │ │ │ │ ├── polygonZkevm.json │ │ │ │ └── zksync.json │ │ │ ├── index.ts │ │ │ ├── token-amount.test.ts │ │ │ ├── token-amount.ts │ │ │ ├── token.test.ts │ │ │ ├── token.ts │ │ │ ├── transform.test.ts │ │ │ ├── transform.ts │ │ │ ├── utils.test.ts │ │ │ └── utils.ts │ │ ├── transaction.ts │ │ ├── utils │ │ │ ├── abi.test.ts │ │ │ ├── abi.ts │ │ │ ├── bignumber.test.ts │ │ │ ├── bignumber.ts │ │ │ ├── bps.test.ts │ │ │ ├── bps.ts │ │ │ ├── error.test.ts │ │ │ ├── error.ts │ │ │ ├── http.ts │ │ │ ├── index.ts │ │ │ ├── web3.test.ts │ │ │ └── web3.ts │ │ ├── web3-toolkit.test.ts │ │ └── web3-toolkit.ts │ ├── test │ │ ├── init.ts │ │ └── web3-toolkit.test.ts │ ├── tsconfig.build.json │ └── tsconfig.json ├── core │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── abis │ │ │ ├── Agent.json │ │ │ ├── Permit2.json │ │ │ └── Router.json │ │ ├── configs.ts │ │ ├── constants.ts │ │ ├── contracts │ │ │ ├── Agent.ts │ │ │ ├── Permit2.ts │ │ │ ├── Router.ts │ │ │ ├── common.ts │ │ │ ├── factories │ │ │ │ ├── Agent__factory.ts │ │ │ │ ├── Permit2__factory.ts │ │ │ │ ├── Router__factory.ts │ │ │ │ └── index.ts │ │ │ └── index.ts │ │ ├── index.ts │ │ ├── logic-types.test.ts │ │ ├── logic-types.ts │ │ ├── logic-utils.test.ts │ │ ├── logic-utils.ts │ │ ├── logic.ts │ │ ├── router-kit.test.ts │ │ ├── router-kit.ts │ │ ├── router-utils.test.ts │ │ └── router-utils.ts │ ├── tsconfig.build.json │ └── tsconfig.json ├── lending │ ├── .mocharc.js │ ├── CHANGELOG.md │ ├── README.md │ ├── hardhat.config.ts │ ├── package.json │ ├── src │ │ ├── adapter.config.ts │ │ ├── adapter.test.ts │ │ ├── adapter.ts │ │ ├── adapter.type.ts │ │ ├── adapter.utils.test.ts │ │ ├── adapter.utils.ts │ │ ├── index.ts │ │ ├── protocol.portfolio.ts │ │ ├── protocol.ts │ │ ├── protocol.type.ts │ │ ├── protocol.utils.ts │ │ ├── protocols │ │ │ ├── aave-v2 │ │ │ │ ├── abis │ │ │ │ │ ├── AToken.json │ │ │ │ │ ├── ETHPriceFeed.json │ │ │ │ │ ├── PriceOracle.json │ │ │ │ │ └── ProtocolDataProvider.json │ │ │ │ ├── adapter.test.ts │ │ │ │ ├── configs.ts │ │ │ │ ├── contracts │ │ │ │ │ ├── AToken.ts │ │ │ │ │ ├── ETHPriceFeed.ts │ │ │ │ │ ├── PriceOracle.ts │ │ │ │ │ ├── ProtocolDataProvider.ts │ │ │ │ │ ├── common.ts │ │ │ │ │ ├── factories │ │ │ │ │ │ ├── AToken__factory.ts │ │ │ │ │ │ ├── ETHPriceFeed__factory.ts │ │ │ │ │ │ ├── PriceOracle__factory.ts │ │ │ │ │ │ ├── ProtocolDataProvider__factory.ts │ │ │ │ │ │ └── index.ts │ │ │ │ │ └── index.ts │ │ │ │ ├── index.ts │ │ │ │ ├── lending-protocol.test.ts │ │ │ │ ├── lending-protocol.ts │ │ │ │ └── tokens │ │ │ │ │ └── index.ts │ │ │ ├── aave-v3 │ │ │ │ ├── abis │ │ │ │ │ ├── AToken.json │ │ │ │ │ ├── AaveOracle.json │ │ │ │ │ ├── Pool.json │ │ │ │ │ └── PoolDataProvider.json │ │ │ │ ├── adapter.test.ts │ │ │ │ ├── configs.ts │ │ │ │ ├── contracts │ │ │ │ │ ├── AToken.ts │ │ │ │ │ ├── AaveOracle.ts │ │ │ │ │ ├── Pool.ts │ │ │ │ │ ├── PoolDataProvider.ts │ │ │ │ │ ├── common.ts │ │ │ │ │ ├── factories │ │ │ │ │ │ ├── AToken__factory.ts │ │ │ │ │ │ ├── AaveOracle__factory.ts │ │ │ │ │ │ ├── PoolDataProvider__factory.ts │ │ │ │ │ │ ├── Pool__factory.ts │ │ │ │ │ │ └── index.ts │ │ │ │ │ └── index.ts │ │ │ │ ├── index.ts │ │ │ │ ├── lending-protocol.test.ts │ │ │ │ ├── lending-protocol.ts │ │ │ │ └── tokens │ │ │ │ │ └── index.ts │ │ │ ├── compound-v3 │ │ │ │ ├── abis │ │ │ │ │ └── Comet.json │ │ │ │ ├── adapter.test.ts │ │ │ │ ├── config.test.ts │ │ │ │ ├── configs.ts │ │ │ │ ├── constants.ts │ │ │ │ ├── contracts │ │ │ │ │ ├── Comet.ts │ │ │ │ │ ├── common.ts │ │ │ │ │ ├── factories │ │ │ │ │ │ ├── Comet__factory.ts │ │ │ │ │ │ └── index.ts │ │ │ │ │ └── index.ts │ │ │ │ ├── index.ts │ │ │ │ ├── lending-protocol.test.ts │ │ │ │ ├── lending-protocol.ts │ │ │ │ ├── tokens │ │ │ │ │ └── index.ts │ │ │ │ └── utils.ts │ │ │ ├── index.ts │ │ │ ├── morphoblue │ │ │ │ ├── abis │ │ │ │ │ ├── Irm.json │ │ │ │ │ ├── Morpho.json │ │ │ │ │ ├── Oracle.json │ │ │ │ │ └── PriceFeed.json │ │ │ │ ├── adapter.test.ts │ │ │ │ ├── configs.ts │ │ │ │ ├── contracts │ │ │ │ │ ├── Irm.ts │ │ │ │ │ ├── Morpho.ts │ │ │ │ │ ├── Oracle.ts │ │ │ │ │ ├── PriceFeed.ts │ │ │ │ │ ├── common.ts │ │ │ │ │ ├── factories │ │ │ │ │ │ ├── Irm__factory.ts │ │ │ │ │ │ ├── Morpho__factory.ts │ │ │ │ │ │ ├── Oracle__factory.ts │ │ │ │ │ │ ├── PriceFeed__factory.ts │ │ │ │ │ │ └── index.ts │ │ │ │ │ └── index.ts │ │ │ │ ├── index.ts │ │ │ │ ├── lending-protocol.test.ts │ │ │ │ ├── lending-protocol.ts │ │ │ │ └── tokens │ │ │ │ │ └── index.ts │ │ │ ├── radiant-v2 │ │ │ │ ├── abis │ │ │ │ │ ├── AToken.json │ │ │ │ │ ├── PriceOracle.json │ │ │ │ │ └── ProtocolDataProvider.json │ │ │ │ ├── adapter.test.ts │ │ │ │ ├── configs.ts │ │ │ │ ├── contracts │ │ │ │ │ ├── AToken.ts │ │ │ │ │ ├── PriceOracle.ts │ │ │ │ │ ├── ProtocolDataProvider.ts │ │ │ │ │ ├── common.ts │ │ │ │ │ ├── factories │ │ │ │ │ │ ├── AToken__factory.ts │ │ │ │ │ │ ├── PriceOracle__factory.ts │ │ │ │ │ │ ├── ProtocolDataProvider__factory.ts │ │ │ │ │ │ └── index.ts │ │ │ │ │ └── index.ts │ │ │ │ ├── index.ts │ │ │ │ ├── lending-protocol.test.ts │ │ │ │ ├── lending-protocol.ts │ │ │ │ └── tokens │ │ │ │ │ ├── data │ │ │ │ │ └── arbitrum.json │ │ │ │ │ └── index.ts │ │ │ └── spark │ │ │ │ ├── abis │ │ │ │ ├── AToken.json │ │ │ │ ├── AaveOracle.json │ │ │ │ ├── Pool.json │ │ │ │ └── PoolDataProvider.json │ │ │ │ ├── adapter.test.ts │ │ │ │ ├── configs.ts │ │ │ │ ├── contracts │ │ │ │ ├── AToken.ts │ │ │ │ ├── AaveOracle.ts │ │ │ │ ├── DebtTokenBase.ts │ │ │ │ ├── Pool.ts │ │ │ │ ├── PoolAddressesProvider.ts │ │ │ │ ├── PoolDataProvider.ts │ │ │ │ ├── SparkFlashLoanCallback.ts │ │ │ │ ├── common.ts │ │ │ │ ├── factories │ │ │ │ │ ├── AToken__factory.ts │ │ │ │ │ ├── AaveOracle__factory.ts │ │ │ │ │ ├── DebtTokenBase__factory.ts │ │ │ │ │ ├── PoolAddressesProvider__factory.ts │ │ │ │ │ ├── PoolDataProvider__factory.ts │ │ │ │ │ ├── Pool__factory.ts │ │ │ │ │ ├── SparkFlashLoanCallback__factory.ts │ │ │ │ │ └── index.ts │ │ │ │ └── index.ts │ │ │ │ ├── index.ts │ │ │ │ ├── lending-protocol.test.ts │ │ │ │ ├── lending-protocol.ts │ │ │ │ └── tokens │ │ │ │ └── index.ts │ │ ├── swapper.ts │ │ ├── swapper.type.ts │ │ └── swappers │ │ │ ├── index.ts │ │ │ ├── openocean-v2 │ │ │ ├── configs.ts │ │ │ ├── index.ts │ │ │ ├── lending-swapper.test.ts │ │ │ └── lending-swapper.ts │ │ │ └── paraswap-v5 │ │ │ ├── configs.ts │ │ │ ├── index.ts │ │ │ └── lending-swapper.ts │ ├── test │ │ ├── hooks.ts │ │ ├── transactions │ │ │ ├── close.test.ts │ │ │ ├── collateral-swap.test.ts │ │ │ ├── debt-swap.test.ts │ │ │ ├── deleverage.test.ts │ │ │ ├── leverage-collateral.test.ts │ │ │ ├── leverage-debt.test.ts │ │ │ ├── open-collateral.test.ts │ │ │ ├── open-debt.test.ts │ │ │ ├── zap-borrow.test.ts │ │ │ ├── zap-repay.test.ts │ │ │ ├── zap-supply.test.ts │ │ │ └── zap-withdraw.test.ts │ │ ├── unit-test-init.ts │ │ └── utils │ │ │ ├── aave-v2.ts │ │ │ ├── aave-v3.ts │ │ │ ├── compound-v3.ts │ │ │ ├── helpers.ts │ │ │ ├── index.ts │ │ │ ├── morphoblue.ts │ │ │ ├── radiant-v2.ts │ │ │ ├── spark.ts │ │ │ └── utils.ts │ ├── tsconfig.build.json │ └── tsconfig.json ├── smart-accounts │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── abis │ │ │ └── Executor.json │ │ ├── account.test.ts │ │ ├── account.ts │ │ ├── configs.ts │ │ ├── contracts │ │ │ ├── Executor.ts │ │ │ ├── common.ts │ │ │ ├── factories │ │ │ │ ├── Executor__factory.ts │ │ │ │ └── index.ts │ │ │ └── index.ts │ │ └── index.ts │ ├── tsconfig.build.json │ └── tsconfig.json └── test-helpers │ ├── .env.arbitrum │ ├── .env.mainnet │ ├── .env.polygon │ ├── CHANGELOG.md │ ├── README.md │ ├── hardhat.config.ts │ ├── package.json │ ├── src │ ├── chai-matchers │ │ ├── change-balance.ts │ │ ├── index.ts │ │ └── types.ts │ ├── hooks │ │ ├── index.ts │ │ └── network.ts │ ├── index.ts │ └── utils │ │ ├── faucet.ts │ │ ├── index.ts │ │ ├── network.ts │ │ └── web3.ts │ ├── test │ ├── arbitrum │ │ └── faucet.test.ts │ ├── common │ │ └── network.test.ts │ ├── mainnet │ │ └── faucet.test.ts │ └── polygon │ │ └── faucet.test.ts │ ├── tsconfig.build.json │ └── tsconfig.json ├── tsconfig.base.json └── yarn.lock /.changeset/README.md: -------------------------------------------------------------------------------- 1 | # Changesets 2 | 3 | Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works 4 | with multi-package repos, or single-package repos to help you version and publish your code. You can 5 | find the full documentation for it [in our repository](https://github.com/changesets/changesets) 6 | 7 | We have a quick list of common questions to get you started engaging with this project in 8 | [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) 9 | -------------------------------------------------------------------------------- /.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@2.3.0/schema.json", 3 | "changelog": ["@changesets/cli/changelog", { "repo": "dinngo/protocolink-js-sdk" }], 4 | "commit": false, 5 | "fixed": [], 6 | "linked": [], 7 | "access": "public", 8 | "baseBranch": "master", 9 | "updateInternalDependencies": "patch", 10 | "ignore": [] 11 | } 12 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | tmp 4 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'], 3 | rules: { 4 | 'max-len': ['error', { code: 120, ignoreUrls: true, ignoreStrings: true, ignorePattern: 'class [a-zA-Z]+' }], 5 | '@typescript-eslint/no-empty-function': 'off', 6 | '@typescript-eslint/no-explicit-any': 'off', 7 | '@typescript-eslint/no-non-null-assertion': 'off', 8 | '@typescript-eslint/no-unused-vars': [ 9 | 'warn', 10 | { argsIgnorePattern: '^_', varsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' }, 11 | ], 12 | }, 13 | }; 14 | -------------------------------------------------------------------------------- /.github/workflows/e2e-test.yml: -------------------------------------------------------------------------------- 1 | name: E2E Test 2 | 3 | on: 4 | push: 5 | pull_request: 6 | 7 | env: 8 | MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }} 9 | 10 | jobs: 11 | run-e2e-test: 12 | name: Run e2e test 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v3 17 | 18 | - name: Setup Node 19 | uses: actions/setup-node@v3 20 | with: 21 | node-version: 16 22 | 23 | - name: Install dependencies 24 | run: yarn install 25 | 26 | - name: Build packages 27 | run: | 28 | yarn workspace @protocolink/common build 29 | yarn workspace @protocolink/core build 30 | yarn workspace @protocolink/test-helpers build 31 | yarn workspace @protocolink/smart-accounts build 32 | yarn workspace @protocolink/api build 33 | 34 | - name: Run e2e test 35 | run: yarn test:e2e 36 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | 3 | on: 4 | push: 5 | pull_request: 6 | 7 | jobs: 8 | run-linters: 9 | name: Run linters 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v3 14 | 15 | - name: Setup Node 16 | uses: actions/setup-node@v3 17 | with: 18 | node-version: 16 19 | 20 | - name: Install dependencies 21 | run: yarn install 22 | 23 | - name: Run linters 24 | uses: wearerequired/lint-action@v2 25 | with: 26 | eslint: true 27 | prettier: true 28 | -------------------------------------------------------------------------------- /.github/workflows/unit-test.yml: -------------------------------------------------------------------------------- 1 | name: Unit Test 2 | 3 | on: 4 | push: 5 | pull_request: 6 | 7 | env: 8 | MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }} 9 | OPTIMISM_RPC_URL: ${{ secrets.OPTIMISM_RPC_URL }} 10 | BNB_RPC_URL: ${{ secrets.BNB_RPC_URL }} 11 | GNOSIS_RPC_URL: ${{ secrets.GNOSIS_RPC_URL }} 12 | POLYGON_RPC_URL: ${{ secrets.POLYGON_RPC_URL }} 13 | ZKSYNC_RPC_URL: ${{ secrets.ZKSYNC_RPC_URL }} 14 | METIS_RPC_URL: ${{ secrets.METIS_RPC_URL }} 15 | BASE_RPC_URL: ${{ secrets.BASE_RPC_URL }} 16 | ARBITRUM_RPC_URL: ${{ secrets.ARBITRUM_RPC_URL }} 17 | AVALANCHE_RPC_URL: ${{ secrets.AVALANCHE_RPC_URL }} 18 | ZEROEX_API_KEY: ${{ secrets.ZEROEX_API_KEY }} 19 | 20 | jobs: 21 | run-unit-test: 22 | name: Run unit test 23 | runs-on: ubuntu-latest 24 | steps: 25 | - name: Checkout 26 | uses: actions/checkout@v3 27 | 28 | - name: Setup Node 29 | uses: actions/setup-node@v3 30 | with: 31 | node-version: 16 32 | 33 | - name: Install dependencies 34 | run: yarn install 35 | 36 | - name: Build packages 37 | run: | 38 | yarn workspace @protocolink/common build 39 | yarn workspace @protocolink/core build 40 | yarn workspace @protocolink/test-helpers build 41 | yarn workspace @protocolink/smart-accounts build 42 | yarn workspace @protocolink/api build 43 | 44 | - name: Run unit test 45 | run: yarn test:unit 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | .DS_Store 3 | node_modules 4 | dist 5 | tmp 6 | cache 7 | -------------------------------------------------------------------------------- /.mocharc.js: -------------------------------------------------------------------------------- 1 | // https://github.com/mochajs/mocha/blob/master/example/config/.mocharc.js 2 | 3 | module.exports = { 4 | extension: 'ts', 5 | require: ['ts-node/register', '@nomicfoundation/hardhat-chai-matchers/internal/add-chai-matchers'], 6 | timeout: 30000, 7 | }; 8 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | .changeset 2 | .github 3 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "singleQuote": true, 4 | "semi": true, 5 | "printWidth": 120 6 | } 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 DINNGO 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /hardhat.config.ts: -------------------------------------------------------------------------------- 1 | import '@nomicfoundation/hardhat-chai-matchers'; 2 | 3 | import { HardhatUserConfig } from 'hardhat/config'; 4 | 5 | const config: HardhatUserConfig = { 6 | networks: { 7 | hardhat: { 8 | chainId: process.env.CHAIN_ID ? parseInt(process.env.CHAIN_ID) : 1, 9 | gasPrice: 0, 10 | initialBaseFeePerGas: 0, 11 | accounts: { 12 | mnemonic: 'test test test test test test test test test test test logic', 13 | path: "m/44'/60'/0'/0", 14 | initialIndex: 0, 15 | }, 16 | forking: { 17 | url: process.env.HTTP_RPC_URL || process.env.MAINNET_RPC_URL || 'https://eth.llamarpc.com', 18 | }, 19 | }, 20 | }, 21 | mocha: { timeout: 1200000, retries: 3 }, 22 | }; 23 | 24 | export default config; 25 | -------------------------------------------------------------------------------- /packages/api/README.md: -------------------------------------------------------------------------------- 1 | # @protocolink/api 2 | 3 | The api sdk for Protocolink. 4 | 5 | ## Install 6 | 7 | Install the package via `npm`: 8 | 9 | ```sh 10 | npm install @protocolink/api 11 | ``` 12 | 13 | or `yarn`: 14 | 15 | ```sh 16 | yarn add @protocolink/api 17 | ``` 18 | -------------------------------------------------------------------------------- /packages/api/examples/aave-v2/borrow.ts: -------------------------------------------------------------------------------- 1 | import * as api from '@protocolink/api'; 2 | import * as logics from '@protocolink/logics'; 3 | 4 | // interface BorrowFields { 5 | // interestRateMode: logics.aavev2.InterestRateMode; 6 | // output: { 7 | // token: { 8 | // chainId: number; 9 | // address: string; 10 | // decimals: number; 11 | // symbol: string; 12 | // name: string; 13 | // }; 14 | // amount: string; 15 | // }; 16 | // } 17 | 18 | // interface BorrowLogic { 19 | // rid: string; 20 | // fields: BorrowFields; 21 | // } 22 | 23 | (async () => { 24 | const chainId = 1; 25 | 26 | const tokenList = await api.protocols.aavev2.getBorrowTokenList(chainId); 27 | const underlyingToken = tokenList[0]; 28 | console.log('underlyingToken :>> ', JSON.stringify(underlyingToken, null, 2)); 29 | 30 | const borrowLogic = await api.protocols.aavev2.newBorrowLogic({ 31 | interestRateMode: logics.aavev2.InterestRateMode.variable, 32 | output: { 33 | token: underlyingToken, 34 | amount: '10', 35 | }, 36 | }); 37 | console.log('borrowLogic :>> ', JSON.stringify(borrowLogic, null, 2)); 38 | })(); 39 | -------------------------------------------------------------------------------- /packages/api/examples/aave-v3/borrow.ts: -------------------------------------------------------------------------------- 1 | import * as api from '@protocolink/api'; 2 | import * as logics from '@protocolink/logics'; 3 | 4 | // interface BorrowFields { 5 | // interestRateMode: logics.aavev3.InterestRateMode; 6 | // output: { 7 | // token: { 8 | // chainId: number; 9 | // address: string; 10 | // decimals: number; 11 | // symbol: string; 12 | // name: string; 13 | // }; 14 | // amount: string; 15 | // }; 16 | // } 17 | 18 | // interface BorrowLogic { 19 | // rid: string; 20 | // fields: BorrowFields; 21 | // } 22 | 23 | (async () => { 24 | const chainId = 1; 25 | 26 | const tokenList = await api.protocols.aavev3.getBorrowTokenList(chainId); 27 | const underlyingToken = tokenList[0]; 28 | console.log('underlyingToken :>> ', JSON.stringify(underlyingToken, null, 2)); 29 | 30 | const borrowLogic = await api.protocols.aavev3.newBorrowLogic({ 31 | interestRateMode: logics.aavev3.InterestRateMode.variable, 32 | output: { 33 | token: underlyingToken, 34 | amount: '10', 35 | }, 36 | }); 37 | console.log('borrowLogic :>> ', JSON.stringify(borrowLogic, null, 2)); 38 | })(); 39 | -------------------------------------------------------------------------------- /packages/api/examples/compound-v3/borrow.ts: -------------------------------------------------------------------------------- 1 | import * as api from '@protocolink/api'; 2 | import * as logics from '@protocolink/logics'; 3 | 4 | // interface BorrowFields { 5 | // marketId: string; 6 | // output: { 7 | // token: { 8 | // chainId: number; 9 | // address: string; 10 | // decimals: number; 11 | // symbol: string; 12 | // name: string; 13 | // }; 14 | // amount: string; 15 | // }; 16 | // } 17 | 18 | // interface BorrowLogic { 19 | // rid: string; 20 | // fields: BorrowFields; 21 | // } 22 | 23 | (async () => { 24 | const chainId = 1; 25 | const marketId = logics.compoundv3.MarketId.USDC; 26 | 27 | const tokenList = await api.protocols.compoundv3.getBorrowTokenList(chainId); 28 | const baseToken = tokenList[marketId][0]; 29 | console.log('baseToken :>> ', JSON.stringify(baseToken, null, 2)); 30 | 31 | const borrowLogic = await api.protocols.compoundv3.newBorrowLogic({ 32 | marketId, 33 | output: { 34 | token: baseToken, 35 | amount: '10', 36 | }, 37 | }); 38 | console.log('borrowLogic :>> ', JSON.stringify(borrowLogic, null, 2)); 39 | })(); 40 | -------------------------------------------------------------------------------- /packages/api/examples/compound-v3/claim.ts: -------------------------------------------------------------------------------- 1 | import * as api from '@protocolink/api'; 2 | import * as logics from '@protocolink/logics'; 3 | 4 | // interface ClaimParams { 5 | // marketId: string; 6 | // owner: string; 7 | // } 8 | 9 | // interface ClaimFields { 10 | // marketId: string; 11 | // owner: string; 12 | // output: { 13 | // token: { 14 | // chainId: number; 15 | // address: string; 16 | // decimals: number; 17 | // symbol: string; 18 | // name: string; 19 | // }; 20 | // amount: string; 21 | // }; 22 | // } 23 | 24 | // interface ClaimLogic { 25 | // rid: string; 26 | // fields: ClaimFields; 27 | // } 28 | 29 | (async () => { 30 | const chainId = 1; 31 | const marketId = logics.compoundv3.MarketId.USDC; 32 | const account = '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa'; 33 | 34 | const tokenList = await api.protocols.compoundv3.getClaimTokenList(chainId); 35 | const COMP = tokenList[0]; 36 | console.log('COMP :>> ', JSON.stringify(COMP, null, 2)); 37 | 38 | const claimQuotation = await api.protocols.compoundv3.getClaimQuotation(chainId, { 39 | marketId, 40 | owner: account, 41 | }); 42 | console.log('claimQuotation :>> ', JSON.stringify(claimQuotation, null, 2)); 43 | 44 | const claimLogic = await api.protocols.compoundv3.newClaimLogic(claimQuotation); 45 | console.log('claimLogic :>> ', JSON.stringify(claimLogic, null, 2)); 46 | })(); 47 | -------------------------------------------------------------------------------- /packages/api/examples/compound-v3/supply-collateral.ts: -------------------------------------------------------------------------------- 1 | import * as api from '@protocolink/api'; 2 | import * as logics from '@protocolink/logics'; 3 | 4 | // interface SupplyCollateralFields { 5 | // marketId: string; 6 | // input: { 7 | // token: { 8 | // chainId: number; 9 | // address: string; 10 | // decimals: number; 11 | // symbol: string; 12 | // name: string; 13 | // }; 14 | // amount: string; 15 | // }; 16 | // } 17 | 18 | // interface SupplyCollateralLogic { 19 | // rid: string; 20 | // fields: SupplyCollateralFields; 21 | // } 22 | 23 | (async () => { 24 | const chainId = 1; 25 | const marketId = logics.compoundv3.MarketId.USDC; 26 | 27 | const tokenList = await api.protocols.compoundv3.getSupplyCollateralTokenList(chainId); 28 | const asset = tokenList[marketId][0]; 29 | console.log('asset :>> ', JSON.stringify(asset, null, 2)); 30 | 31 | const supplyCollateralLogic = await api.protocols.compoundv3.newSupplyCollateralLogic({ 32 | marketId, 33 | input: { 34 | token: asset, 35 | amount: '10', 36 | }, 37 | }); 38 | console.log('supplyCollateralLogic :>> ', JSON.stringify(supplyCollateralLogic, null, 2)); 39 | })(); 40 | -------------------------------------------------------------------------------- /packages/api/examples/compound-v3/withdraw-collateral.ts: -------------------------------------------------------------------------------- 1 | import * as api from '@protocolink/api'; 2 | import * as logics from '@protocolink/logics'; 3 | 4 | // interface WithdrawCollateralFields { 5 | // marketId: string; 6 | // input: { 7 | // token: { 8 | // chainId: number; 9 | // address: string; 10 | // decimals: number; 11 | // symbol: string; 12 | // name: string; 13 | // }; 14 | // amount: string; 15 | // }; 16 | // } 17 | 18 | // interface WithdrawCollateralLogic { 19 | // rid: string; 20 | // fields: WithdrawCollateralFields; 21 | // } 22 | 23 | (async () => { 24 | const chainId = 1; 25 | const marketId = logics.compoundv3.MarketId.USDC; 26 | 27 | const tokenList = await api.protocols.compoundv3.getWithdrawCollateralTokenList(chainId); 28 | const asset = tokenList[marketId][0]; 29 | console.log('asset :>> ', JSON.stringify(asset, null, 2)); 30 | 31 | const withdrawCollateralLogic = await api.protocols.compoundv3.newWithdrawCollateralLogic({ 32 | marketId, 33 | output: { 34 | token: asset, 35 | amount: '10', 36 | }, 37 | }); 38 | console.log('withdrawCollateralLogic :>> ', JSON.stringify(withdrawCollateralLogic, null, 2)); 39 | })(); 40 | -------------------------------------------------------------------------------- /packages/api/examples/iolend/borrow.ts: -------------------------------------------------------------------------------- 1 | import * as api from '@protocolink/api'; 2 | import * as logics from '@protocolink/logics'; 3 | 4 | // interface BorrowFields { 5 | // interestRateMode: logics.iolend.InterestRateMode; 6 | // output: { 7 | // token: { 8 | // chainId: number; 9 | // address: string; 10 | // decimals: number; 11 | // symbol: string; 12 | // name: string; 13 | // }; 14 | // amount: string; 15 | // }; 16 | // } 17 | 18 | // interface BorrowLogic { 19 | // rid: string; 20 | // fields: BorrowFields; 21 | // } 22 | 23 | (async () => { 24 | const chainId = 8822; 25 | 26 | const tokenList = await api.protocols.iolend.getBorrowTokenList(chainId); 27 | const underlyingToken = tokenList[0]; 28 | console.log('underlyingToken :>> ', JSON.stringify(underlyingToken, null, 2)); 29 | 30 | const borrowLogic = await api.protocols.iolend.newBorrowLogic({ 31 | interestRateMode: logics.iolend.InterestRateMode.variable, 32 | output: { 33 | token: underlyingToken, 34 | amount: '10', 35 | }, 36 | }); 37 | console.log('borrowLogic :>> ', JSON.stringify(borrowLogic, null, 2)); 38 | })(); 39 | -------------------------------------------------------------------------------- /packages/api/examples/morphoblue/borrow.ts: -------------------------------------------------------------------------------- 1 | import * as api from '@protocolink/api'; 2 | 3 | // interface BorrowFields { 4 | // marketId: string; 5 | // output: { 6 | // token: { 7 | // chainId: number; 8 | // address: string; 9 | // decimals: number; 10 | // symbol: string; 11 | // name: string; 12 | // }; 13 | // amount: string; 14 | // }; 15 | // } 16 | 17 | // interface BorrowLogic { 18 | // rid: string; 19 | // fields: BorrowFields; 20 | // } 21 | 22 | (async () => { 23 | const chainId = 1; 24 | const marketId = '0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc'; 25 | 26 | const tokenList = await api.protocols.morphoblue.getBorrowTokenList(chainId); 27 | const loanToken = tokenList[marketId][0]; 28 | console.log('loanToken :>> ', JSON.stringify(loanToken, null, 2)); 29 | 30 | const borrowLogic = await api.protocols.morphoblue.newBorrowLogic({ 31 | marketId, 32 | output: { 33 | token: loanToken, 34 | amount: '10', 35 | }, 36 | }); 37 | console.log('borrowLogic :>> ', JSON.stringify(borrowLogic, null, 2)); 38 | })(); 39 | -------------------------------------------------------------------------------- /packages/api/examples/morphoblue/supply-collateral.ts: -------------------------------------------------------------------------------- 1 | import * as api from '@protocolink/api'; 2 | 3 | // interface SupplyCollateralFields { 4 | // marketId: string; 5 | // input: { 6 | // token: { 7 | // chainId: number; 8 | // address: string; 9 | // decimals: number; 10 | // symbol: string; 11 | // name: string; 12 | // }; 13 | // amount: string; 14 | // }; 15 | // } 16 | 17 | // interface SupplyCollateralLogic { 18 | // rid: string; 19 | // fields: SupplyCollateralFields; 20 | // } 21 | 22 | (async () => { 23 | const chainId = 1; 24 | const marketId = '0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc'; 25 | 26 | const tokenList = await api.protocols.morphoblue.getSupplyCollateralTokenList(chainId); 27 | const asset = tokenList[marketId][0]; 28 | console.log('asset :>> ', JSON.stringify(asset, null, 2)); 29 | 30 | const supplyCollateralLogic = await api.protocols.morphoblue.newSupplyCollateralLogic({ 31 | marketId, 32 | input: { 33 | token: asset, 34 | amount: '10', 35 | }, 36 | }); 37 | console.log('supplyCollateralLogic :>> ', JSON.stringify(supplyCollateralLogic, null, 2)); 38 | })(); 39 | -------------------------------------------------------------------------------- /packages/api/examples/morphoblue/supply.ts: -------------------------------------------------------------------------------- 1 | import * as api from '@protocolink/api'; 2 | 3 | // interface SupplyFields { 4 | // marketId: string; 5 | // input: { 6 | // token: { 7 | // chainId: number; 8 | // address: string; 9 | // decimals: number; 10 | // symbol: string; 11 | // name: string; 12 | // }; 13 | // amount: string; 14 | // }; 15 | // } 16 | 17 | // interface SupplyLogic { 18 | // rid: string; 19 | // fields: SupplyFields; 20 | // } 21 | 22 | (async () => { 23 | const chainId = 1; 24 | const marketId = '0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc'; 25 | 26 | const tokenList = await api.protocols.morphoblue.getSupplyTokenList(chainId); 27 | const asset = tokenList[marketId][0]; 28 | console.log('asset :>> ', JSON.stringify(asset, null, 2)); 29 | 30 | const supplyLogic = await api.protocols.morphoblue.newSupplyLogic({ 31 | marketId, 32 | input: { 33 | token: asset, 34 | amount: '10', 35 | }, 36 | }); 37 | console.log('supplyLogic :>> ', JSON.stringify(supplyLogic, null, 2)); 38 | })(); 39 | -------------------------------------------------------------------------------- /packages/api/examples/morphoblue/withdraw-collateral.ts: -------------------------------------------------------------------------------- 1 | import * as api from '@protocolink/api'; 2 | 3 | // interface WithdrawCollateralFields { 4 | // marketId: string; 5 | // input: { 6 | // token: { 7 | // chainId: number; 8 | // address: string; 9 | // decimals: number; 10 | // symbol: string; 11 | // name: string; 12 | // }; 13 | // amount: string; 14 | // }; 15 | // } 16 | 17 | // interface WithdrawCollateralLogic { 18 | // rid: string; 19 | // fields: WithdrawCollateralFields; 20 | // } 21 | 22 | (async () => { 23 | const chainId = 1; 24 | const marketId = '0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc'; 25 | 26 | const tokenList = await api.protocols.morphoblue.getWithdrawCollateralTokenList(chainId); 27 | const asset = tokenList[marketId][0]; 28 | console.log('asset :>> ', JSON.stringify(asset, null, 2)); 29 | 30 | const withdrawCollateralLogic = await api.protocols.morphoblue.newWithdrawCollateralLogic({ 31 | marketId, 32 | output: { 33 | token: asset, 34 | amount: '10', 35 | }, 36 | }); 37 | console.log('withdrawCollateralLogic :>> ', JSON.stringify(withdrawCollateralLogic, null, 2)); 38 | })(); 39 | -------------------------------------------------------------------------------- /packages/api/examples/morphoblue/withdraw.ts: -------------------------------------------------------------------------------- 1 | import * as api from '@protocolink/api'; 2 | 3 | // interface WithdrawFields { 4 | // marketId: string; 5 | // input: { 6 | // token: { 7 | // chainId: number; 8 | // address: string; 9 | // decimals: number; 10 | // symbol: string; 11 | // name: string; 12 | // }; 13 | // amount: string; 14 | // }; 15 | // } 16 | 17 | // interface WithdrawLogic { 18 | // rid: string; 19 | // fields: WithdrawFields; 20 | // } 21 | 22 | (async () => { 23 | const chainId = 1; 24 | const marketId = '0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc'; 25 | 26 | const tokenList = await api.protocols.morphoblue.getWithdrawTokenList(chainId); 27 | const asset = tokenList[marketId][0]; 28 | console.log('asset :>> ', JSON.stringify(asset, null, 2)); 29 | 30 | const withdrawLogic = await api.protocols.morphoblue.newWithdrawLogic({ 31 | marketId, 32 | output: { 33 | token: asset, 34 | amount: '10', 35 | }, 36 | }); 37 | console.log('withdrawLogic :>> ', JSON.stringify(withdrawLogic, null, 2)); 38 | })(); 39 | -------------------------------------------------------------------------------- /packages/api/examples/permit2/pull-token.ts: -------------------------------------------------------------------------------- 1 | import * as api from '@protocolink/api'; 2 | 3 | // interface PullTokenFields { 4 | // input: { 5 | // token: { 6 | // chainId: number; 7 | // address: string; 8 | // decimals: number; 9 | // symbol: string; 10 | // name: string; 11 | // }; 12 | // amount: string; 13 | // }; 14 | // } 15 | 16 | // interface PullTokenLogic { 17 | // rid: string; 18 | // fields: PullTokenFields; 19 | // } 20 | 21 | (async () => { 22 | const chainId = 1; 23 | 24 | const tokenList = await api.protocols.permit2.getPullTokenTokenList(chainId); 25 | const tokenIn = tokenList[0]; 26 | console.log('tokenIn :>> ', JSON.stringify(tokenIn, null, 2)); 27 | 28 | const pullTokenLogic = await api.protocols.permit2.newPullTokenLogic({ 29 | input: { 30 | token: tokenIn, 31 | amount: '10', 32 | }, 33 | }); 34 | 35 | console.log('pullTokenLogic :>> ', JSON.stringify(pullTokenLogic, null, 2)); 36 | })(); 37 | -------------------------------------------------------------------------------- /packages/api/examples/radiant-v2/borrow.ts: -------------------------------------------------------------------------------- 1 | import * as api from '@protocolink/api'; 2 | import * as logics from '@protocolink/logics'; 3 | 4 | // interface BorrowFields { 5 | // interestRateMode: logics.radiantv2.InterestRateMode; 6 | // output: { 7 | // token: { 8 | // chainId: number; 9 | // address: string; 10 | // decimals: number; 11 | // symbol: string; 12 | // name: string; 13 | // }; 14 | // amount: string; 15 | // }; 16 | // } 17 | 18 | // interface BorrowLogic { 19 | // rid: string; 20 | // fields: BorrowFields; 21 | // } 22 | 23 | (async () => { 24 | const chainId = 42161; 25 | 26 | const tokenList = await api.protocols.radiantv2.getBorrowTokenList(chainId); 27 | const underlyingToken = tokenList[0]; 28 | console.log('underlyingToken :>> ', JSON.stringify(underlyingToken, null, 2)); 29 | 30 | const borrowLogic = await api.protocols.radiantv2.newBorrowLogic({ 31 | interestRateMode: logics.radiantv2.InterestRateMode.variable, 32 | output: { 33 | token: underlyingToken, 34 | amount: '10', 35 | }, 36 | }); 37 | console.log('borrowLogic :>> ', JSON.stringify(borrowLogic, null, 2)); 38 | })(); 39 | -------------------------------------------------------------------------------- /packages/api/examples/radiant-v2/flash-loan.ts: -------------------------------------------------------------------------------- 1 | import * as api from '@protocolink/api'; 2 | 3 | // import * as common from '@protocolink/common'; 4 | 5 | // interface FlashLoanLogicFields { 6 | // id: string; 7 | // outputs: common.TokenAmounts; 8 | // isLoan: boolean; 9 | // } 10 | 11 | // interface FlashLoanFields { 12 | // id: string; 13 | // outputs: { 14 | // token: { 15 | // chainId: number; 16 | // address: string; 17 | // decimals: number; 18 | // symbol: string; 19 | // name: string; 20 | // }; 21 | // amount: string; 22 | // }[]; 23 | // isLoan: boolean; 24 | // } 25 | 26 | // interface FlashLoanLogic { 27 | // rid: string; 28 | // fields: FlashLoanFields; 29 | // } 30 | 31 | (async () => { 32 | const chainId = 42161; 33 | 34 | const tokenList = await api.protocols.radiantv2.getFlashLoanTokenList(chainId); 35 | const underlyingToken = tokenList[0]; 36 | console.log('underlyingToken :>> ', JSON.stringify(underlyingToken, null, 2)); 37 | 38 | const outputs = [ 39 | { 40 | token: underlyingToken, 41 | amount: '10000', 42 | }, 43 | ]; 44 | 45 | const [flashLoanLoanLogic, flashLoanRepayLogic] = api.protocols.radiantv2.newFlashLoanLogicPair(outputs); 46 | const logics = [flashLoanLoanLogic]; 47 | 48 | logics.push(flashLoanRepayLogic); 49 | console.log('logics :>> ', JSON.stringify(logics, null, 2)); 50 | })(); 51 | -------------------------------------------------------------------------------- /packages/api/examples/spark/borrow.ts: -------------------------------------------------------------------------------- 1 | import * as api from '@protocolink/api'; 2 | import * as logics from '@protocolink/logics'; 3 | 4 | // interface BorrowFields { 5 | // interestRateMode: logics.spark.InterestRateMode; 6 | // output: { 7 | // token: { 8 | // chainId: number; 9 | // address: string; 10 | // decimals: number; 11 | // symbol: string; 12 | // name: string; 13 | // }; 14 | // amount: string; 15 | // }; 16 | // } 17 | 18 | // interface BorrowLogic { 19 | // rid: string; 20 | // fields: BorrowFields; 21 | // } 22 | 23 | (async () => { 24 | const chainId = 1; 25 | 26 | const tokenList = await api.protocols.spark.getBorrowTokenList(chainId); 27 | const underlyingToken = tokenList[0]; 28 | console.log('underlyingToken :>> ', JSON.stringify(underlyingToken, null, 2)); 29 | 30 | const borrowLogic = await api.protocols.spark.newBorrowLogic({ 31 | interestRateMode: logics.spark.InterestRateMode.variable, 32 | output: { 33 | token: underlyingToken, 34 | amount: '10', 35 | }, 36 | }); 37 | console.log('borrowLogic :>> ', JSON.stringify(borrowLogic, null, 2)); 38 | })(); 39 | -------------------------------------------------------------------------------- /packages/api/examples/utility/multi-send.ts: -------------------------------------------------------------------------------- 1 | import * as api from '@protocolink/api'; 2 | 3 | // type MultiSendFields = { 4 | // input: { 5 | // token: { 6 | // chainId: number; 7 | // address: string; 8 | // decimals: number; 9 | // symbol: string; 10 | // name: string; 11 | // }; 12 | // amount: string; 13 | // }; 14 | // recipient: string; 15 | // }[]; 16 | 17 | // interface MultiSendLogic { 18 | // rid: string; 19 | // fields: MultiSendFields; 20 | // } 21 | 22 | (async () => { 23 | const chainId = 1; 24 | 25 | const tokenList = await api.protocols.utility.getMultiSendTokenList(chainId); 26 | const tokenA = tokenList[0]; 27 | const tokenB = tokenList[1]; 28 | console.log('tokenA :>> ', JSON.stringify(tokenA, null, 2)); 29 | console.log('tokenB :>> ', JSON.stringify(tokenB, null, 2)); 30 | 31 | const multiSendLogic = await api.protocols.utility.newMultiSendLogic([ 32 | { 33 | input: { 34 | token: tokenA, 35 | amount: '10', 36 | }, 37 | recipient: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa', 38 | }, 39 | { 40 | input: { 41 | token: tokenB, 42 | amount: '10', 43 | }, 44 | recipient: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB', 45 | }, 46 | ]); 47 | console.log('multiSendLogic :>> ', JSON.stringify(multiSendLogic, null, 2)); 48 | })(); 49 | -------------------------------------------------------------------------------- /packages/api/examples/utility/send-token.ts: -------------------------------------------------------------------------------- 1 | import * as api from '@protocolink/api'; 2 | 3 | // interface SendTokenFields { 4 | // input: { 5 | // token: { 6 | // chainId: number; 7 | // address: string; 8 | // decimals: number; 9 | // symbol: string; 10 | // name: string; 11 | // }; 12 | // amount: string; 13 | // }; 14 | // recipient: string; 15 | // } 16 | 17 | // interface SendTokenLogic { 18 | // rid: string; 19 | // fields: SendTokenFields; 20 | // } 21 | 22 | (async () => { 23 | const chainId = 1; 24 | 25 | const tokenList = await api.protocols.utility.getSendTokenTokenList(chainId); 26 | const tokenIn = tokenList[0]; 27 | console.log('tokenIn :>> ', JSON.stringify(tokenIn, null, 2)); 28 | 29 | const sendTokenLogic = await api.protocols.utility.newSendTokenLogic({ 30 | input: { 31 | token: tokenIn, 32 | amount: '10', 33 | }, 34 | recipient: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa', 35 | }); 36 | console.log('sendTokenLogic :>> ', JSON.stringify(sendTokenLogic, null, 2)); 37 | })(); 38 | -------------------------------------------------------------------------------- /packages/api/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@protocolink/api", 3 | "version": "1.4.8", 4 | "description": "Protocolink API SDK", 5 | "keywords": [ 6 | "furucombo", 7 | "protocolink" 8 | ], 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/dinngo/protocolink-js-sdk.git", 12 | "directory": "packages/api" 13 | }, 14 | "license": "MIT", 15 | "main": "dist/index.js", 16 | "types": "dist/index.d.ts", 17 | "files": [ 18 | "dist/**/*" 19 | ], 20 | "scripts": { 21 | "build": "rm -rf dist && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json", 22 | "format": "yarn sort-package-json", 23 | "lint": "eslint --fix src", 24 | "prepublishOnly": "yarn build", 25 | "test": "mocha", 26 | "test:unit": "mocha --recursive src examples" 27 | }, 28 | "dependencies": { 29 | "@protocolink/common": "^0.5.5", 30 | "@protocolink/core": "^0.6.4", 31 | "@protocolink/logics": "^1.8.9", 32 | "@types/lodash": "^4.14.195", 33 | "@types/uuid": "^9.0.2", 34 | "@uniswap/permit2-sdk": "^1.2.0", 35 | "axios": "^1.3.6", 36 | "axios-retry": "^3.5.1", 37 | "uuid": "^9.0.0" 38 | }, 39 | "devDependencies": { 40 | "@protocolink/test-helpers": "*" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /packages/api/src/index.ts: -------------------------------------------------------------------------------- 1 | export * as protocols from './protocols'; 2 | export * from './api'; 3 | export * from './types'; 4 | -------------------------------------------------------------------------------- /packages/api/src/protocols/aave-v2/borrow.test.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | import { expect } from 'chai'; 3 | import { getBorrowTokenList } from './borrow'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('AaveV2 BorrowLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.aavev2.BorrowLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getBorrowTokenList(chainId); 11 | expect(tokenList).to.have.lengthOf.above(0); 12 | }); 13 | }); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /packages/api/src/protocols/aave-v2/borrow.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type BorrowFields = common.Declasifying; 7 | 8 | export type BorrowLogic = Logic; 9 | 10 | export async function getBorrowTokenList(chainId: number): Promise { 11 | return getProtocolTokenList(chainId, logics.aavev2.BorrowLogic.rid); 12 | } 13 | 14 | export function newBorrowLogic(fields: BorrowFields): BorrowLogic { 15 | return { rid: logics.aavev2.BorrowLogic.rid, fields }; 16 | } 17 | -------------------------------------------------------------------------------- /packages/api/src/protocols/aave-v2/deposit.test.ts: -------------------------------------------------------------------------------- 1 | import { DepositParams, getDepositQuotation, getDepositTokenList } from './deposit'; 2 | import * as common from '@protocolink/common'; 3 | import { expect } from 'chai'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('AaveV2 DepositLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.aavev2.DepositLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getDepositTokenList(chainId); 11 | expect(tokenList).to.have.lengthOf.above(0); 12 | }); 13 | }); 14 | }); 15 | 16 | context('Test getQuotation', async function () { 17 | const chainId = common.ChainId.mainnet; 18 | 19 | const testCases: DepositParams[] = [ 20 | { 21 | input: { token: logics.aavev2.mainnetTokens.ETH, amount: '1' }, 22 | tokenOut: logics.aavev2.mainnetTokens.aWETH, 23 | }, 24 | { 25 | input: { token: logics.aavev2.mainnetTokens.USDC, amount: '1' }, 26 | tokenOut: logics.aavev2.mainnetTokens.aUSDC, 27 | }, 28 | ]; 29 | 30 | testCases.forEach((params, i) => { 31 | it(`case ${i + 1}`, async function () { 32 | const quotation = await getDepositQuotation(chainId, params); 33 | expect(quotation).to.include.all.keys('input', 'output'); 34 | }); 35 | }); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /packages/api/src/protocols/aave-v2/deposit.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type DepositParams = common.Declasifying; 7 | 8 | export type DepositFields = common.Declasifying; 9 | 10 | export type DepositLogic = Logic; 11 | 12 | export async function getDepositTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.aavev2.DepositLogic.rid); 14 | } 15 | 16 | export async function getDepositQuotation( 17 | chainId: number, 18 | params: DepositParams 19 | ): Promise { 20 | return quote(chainId, logics.aavev2.DepositLogic.rid, params); 21 | } 22 | 23 | export function newDepositLogic(fields: DepositFields): DepositLogic { 24 | return { rid: logics.aavev2.DepositLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/aave-v2/flash-loan.ts: -------------------------------------------------------------------------------- 1 | import { FlashLoanFields, FlashLoanLogic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | import { v4 as uuid } from 'uuid'; 6 | 7 | export type FlashLoanParams = common.Declasifying; 8 | 9 | export async function getFlashLoanTokenList(chainId: number): Promise { 10 | return getProtocolTokenList(chainId, logics.aavev2.FlashLoanLogic.rid); 11 | } 12 | 13 | export async function getFlashLoanQuotation( 14 | chainId: number, 15 | params: FlashLoanParams 16 | ): Promise { 17 | return quote(chainId, logics.aavev2.FlashLoanLogic.rid, params); 18 | } 19 | 20 | export function newFlashLoanLogic(fields: FlashLoanFields): FlashLoanLogic { 21 | return { rid: logics.aavev2.FlashLoanLogic.rid, fields }; 22 | } 23 | 24 | export function newFlashLoanLogicPair(loans: FlashLoanFields['loans']): [FlashLoanLogic, FlashLoanLogic] { 25 | const id = uuid(); 26 | return [newFlashLoanLogic({ id, loans, isLoan: true }), newFlashLoanLogic({ id, loans, isLoan: false })]; 27 | } 28 | -------------------------------------------------------------------------------- /packages/api/src/protocols/aave-v2/index.ts: -------------------------------------------------------------------------------- 1 | export * from './borrow'; 2 | export * from './deposit'; 3 | export * from './flash-loan'; 4 | export * from './repay'; 5 | export * from './withdraw'; 6 | -------------------------------------------------------------------------------- /packages/api/src/protocols/aave-v2/repay.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type RepayParams = common.Declasifying; 7 | 8 | export type RepayFields = common.Declasifying; 9 | 10 | export type RepayLogic = Logic; 11 | 12 | export async function getRepayTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.aavev2.RepayLogic.rid); 14 | } 15 | 16 | export async function getRepayQuotation(chainId: number, params: RepayParams): Promise { 17 | return quote(chainId, logics.aavev2.RepayLogic.rid, params); 18 | } 19 | 20 | export function newRepayLogic(fields: RepayFields): RepayLogic { 21 | return { rid: logics.aavev2.RepayLogic.rid, fields }; 22 | } 23 | -------------------------------------------------------------------------------- /packages/api/src/protocols/aave-v2/withdraw.test.ts: -------------------------------------------------------------------------------- 1 | import { WithdrawParams, getWithdrawQuotation, getWithdrawTokenList } from './withdraw'; 2 | import * as common from '@protocolink/common'; 3 | import { expect } from 'chai'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('AaveV2 WithdrawLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.aavev2.WithdrawLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getWithdrawTokenList(chainId); 11 | expect(tokenList).to.have.lengthOf.above(0); 12 | }); 13 | }); 14 | }); 15 | 16 | context('Test getQuotation', async function () { 17 | const chainId = common.ChainId.mainnet; 18 | 19 | const testCases: WithdrawParams[] = [ 20 | { 21 | input: { token: logics.aavev2.mainnetTokens.aWETH, amount: '1' }, 22 | tokenOut: logics.aavev2.mainnetTokens.ETH, 23 | }, 24 | { 25 | input: { token: logics.aavev2.mainnetTokens.aUSDC, amount: '1' }, 26 | tokenOut: logics.aavev2.mainnetTokens.USDC, 27 | }, 28 | ]; 29 | 30 | testCases.forEach((params, i) => { 31 | it(`case ${i + 1}`, async function () { 32 | const quotation = await getWithdrawQuotation(chainId, params); 33 | expect(quotation).to.include.all.keys('input', 'output'); 34 | }); 35 | }); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /packages/api/src/protocols/aave-v2/withdraw.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type WithdrawParams = common.Declasifying; 7 | 8 | export type WithdrawFields = common.Declasifying; 9 | 10 | export type WithdrawLogic = Logic; 11 | 12 | export async function getWithdrawTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.aavev2.WithdrawLogic.rid); 14 | } 15 | 16 | export async function getWithdrawQuotation( 17 | chainId: number, 18 | params: WithdrawParams 19 | ): Promise { 20 | return quote(chainId, logics.aavev2.WithdrawLogic.rid, params); 21 | } 22 | 23 | export function newWithdrawLogic(fields: WithdrawFields): WithdrawLogic { 24 | return { rid: logics.aavev2.WithdrawLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/aave-v3/borrow.test.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | import { expect } from 'chai'; 3 | import { getBorrowTokenList } from './borrow'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('AaveV3 BorrowLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.aavev3.BorrowLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getBorrowTokenList(chainId); 11 | expect(tokenList).to.have.lengthOf.above(0); 12 | }); 13 | }); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /packages/api/src/protocols/aave-v3/borrow.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type BorrowFields = common.Declasifying; 7 | 8 | export type BorrowLogic = Logic; 9 | 10 | export async function getBorrowTokenList(chainId: number): Promise { 11 | return getProtocolTokenList(chainId, logics.aavev3.BorrowLogic.rid); 12 | } 13 | 14 | export function newBorrowLogic(fields: BorrowFields): BorrowLogic { 15 | return { rid: logics.aavev3.BorrowLogic.rid, fields }; 16 | } 17 | -------------------------------------------------------------------------------- /packages/api/src/protocols/aave-v3/flash-loan.ts: -------------------------------------------------------------------------------- 1 | import { FlashLoanFields, FlashLoanLogic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | import { v4 as uuid } from 'uuid'; 6 | 7 | export type FlashLoanParams = common.Declasifying; 8 | 9 | export async function getFlashLoanTokenList(chainId: number): Promise { 10 | return getProtocolTokenList(chainId, logics.aavev3.FlashLoanLogic.rid); 11 | } 12 | 13 | export async function getFlashLoanQuotation( 14 | chainId: number, 15 | params: FlashLoanParams 16 | ): Promise { 17 | return quote(chainId, logics.aavev3.FlashLoanLogic.rid, params); 18 | } 19 | 20 | export function newFlashLoanLogic(fields: FlashLoanFields): FlashLoanLogic { 21 | return { rid: logics.aavev3.FlashLoanLogic.rid, fields }; 22 | } 23 | 24 | export function newFlashLoanLogicPair(loans: FlashLoanFields['loans']): [FlashLoanLogic, FlashLoanLogic] { 25 | const id = uuid(); 26 | return [newFlashLoanLogic({ id, loans, isLoan: true }), newFlashLoanLogic({ id, loans, isLoan: false })]; 27 | } 28 | -------------------------------------------------------------------------------- /packages/api/src/protocols/aave-v3/index.ts: -------------------------------------------------------------------------------- 1 | export * from './borrow'; 2 | export * from './supply'; 3 | export * from './flash-loan'; 4 | export * from './repay'; 5 | export * from './withdraw'; 6 | -------------------------------------------------------------------------------- /packages/api/src/protocols/aave-v3/repay.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type RepayParams = common.Declasifying; 7 | 8 | export type RepayFields = common.Declasifying; 9 | 10 | export type RepayLogic = Logic; 11 | 12 | export async function getRepayTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.aavev3.RepayLogic.rid); 14 | } 15 | 16 | export async function getRepayQuotation(chainId: number, params: RepayParams): Promise { 17 | return quote(chainId, logics.aavev3.RepayLogic.rid, params); 18 | } 19 | 20 | export function newRepayLogic(fields: RepayFields): RepayLogic { 21 | return { rid: logics.aavev3.RepayLogic.rid, fields }; 22 | } 23 | -------------------------------------------------------------------------------- /packages/api/src/protocols/aave-v3/supply.test.ts: -------------------------------------------------------------------------------- 1 | import { SupplyParams, getSupplyQuotation, getSupplyTokenList } from './supply'; 2 | import * as common from '@protocolink/common'; 3 | import { expect } from 'chai'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('AaveV3 SupplyLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.aavev3.SupplyLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getSupplyTokenList(chainId); 11 | expect(tokenList).to.have.lengthOf.above(0); 12 | }); 13 | }); 14 | }); 15 | 16 | context('Test getQuotation', async function () { 17 | const chainId = common.ChainId.mainnet; 18 | 19 | const testCases: SupplyParams[] = [ 20 | { 21 | input: { token: logics.aavev3.mainnetTokens.ETH, amount: '1' }, 22 | tokenOut: logics.aavev3.mainnetTokens.aEthWETH, 23 | }, 24 | { 25 | input: { token: logics.aavev3.mainnetTokens.USDC, amount: '1' }, 26 | tokenOut: logics.aavev3.mainnetTokens.aEthUSDC, 27 | }, 28 | ]; 29 | 30 | testCases.forEach((params, i) => { 31 | it(`case ${i + 1}`, async function () { 32 | const quotation = await getSupplyQuotation(chainId, params); 33 | expect(quotation).to.include.all.keys('input', 'output'); 34 | }); 35 | }); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /packages/api/src/protocols/aave-v3/supply.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type SupplyParams = common.Declasifying; 7 | 8 | export type SupplyFields = common.Declasifying; 9 | 10 | export type SupplyLogic = Logic; 11 | 12 | export async function getSupplyTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.aavev3.SupplyLogic.rid); 14 | } 15 | 16 | export async function getSupplyQuotation( 17 | chainId: number, 18 | params: SupplyParams 19 | ): Promise { 20 | return quote(chainId, logics.aavev3.SupplyLogic.rid, params); 21 | } 22 | 23 | export function newSupplyLogic(fields: SupplyFields): SupplyLogic { 24 | return { rid: logics.aavev3.SupplyLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/aave-v3/withdraw.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type WithdrawParams = common.Declasifying; 7 | 8 | export type WithdrawFields = common.Declasifying; 9 | 10 | export type WithdrawLogic = Logic; 11 | 12 | export async function getWithdrawTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.aavev3.WithdrawLogic.rid); 14 | } 15 | 16 | export async function getWithdrawQuotation( 17 | chainId: number, 18 | params: WithdrawParams 19 | ): Promise { 20 | return quote(chainId, logics.aavev3.WithdrawLogic.rid, params); 21 | } 22 | 23 | export function newWithdrawLogic(fields: WithdrawFields): WithdrawLogic { 24 | return { rid: logics.aavev3.WithdrawLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/balancer-v2/flash-loan.ts: -------------------------------------------------------------------------------- 1 | import { FlashLoanFields, FlashLoanLogic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | import { v4 as uuid } from 'uuid'; 6 | 7 | export type FlashLoanParams = common.Declasifying; 8 | 9 | export async function getFlashLoanTokenList(chainId: number): Promise { 10 | return getProtocolTokenList(chainId, logics.balancerv2.FlashLoanLogic.rid); 11 | } 12 | 13 | export async function getFlashLoanQuotation( 14 | chainId: number, 15 | params: FlashLoanParams 16 | ): Promise { 17 | return quote(chainId, logics.balancerv2.FlashLoanLogic.rid, params); 18 | } 19 | 20 | export function newFlashLoanLogic(fields: FlashLoanFields): FlashLoanLogic { 21 | return { rid: logics.balancerv2.FlashLoanLogic.rid, fields }; 22 | } 23 | 24 | export function newFlashLoanLogicPair(loans: FlashLoanFields['loans']): [FlashLoanLogic, FlashLoanLogic] { 25 | const id = uuid(); 26 | return [newFlashLoanLogic({ id, loans, isLoan: true }), newFlashLoanLogic({ id, loans, isLoan: false })]; 27 | } 28 | -------------------------------------------------------------------------------- /packages/api/src/protocols/balancer-v2/index.ts: -------------------------------------------------------------------------------- 1 | export * from './flash-loan'; 2 | -------------------------------------------------------------------------------- /packages/api/src/protocols/compound-v3/borrow.test.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | import { expect } from 'chai'; 3 | import { getBorrowTokenList } from './borrow'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('CompoundV3 BorrowLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.compoundv3.BorrowLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getBorrowTokenList(chainId); 11 | const marketIds = Object.keys(tokenList); 12 | expect(marketIds).to.have.lengthOf.above(0); 13 | for (const marketId of marketIds) { 14 | expect(tokenList[marketId]).to.have.lengthOf.above(0); 15 | } 16 | }); 17 | }); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /packages/api/src/protocols/compound-v3/borrow.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type BorrowFields = common.Declasifying; 7 | 8 | export type BorrowLogic = Logic; 9 | 10 | export async function getBorrowTokenList(chainId: number): Promise { 11 | return getProtocolTokenList(chainId, logics.compoundv3.BorrowLogic.rid); 12 | } 13 | 14 | export function newBorrowLogic(fields: BorrowFields): BorrowLogic { 15 | return { rid: logics.compoundv3.BorrowLogic.rid, fields }; 16 | } 17 | -------------------------------------------------------------------------------- /packages/api/src/protocols/compound-v3/claim.test.ts: -------------------------------------------------------------------------------- 1 | import { ClaimParams, getClaimQuotation, getClaimTokenList } from './claim'; 2 | import * as common from '@protocolink/common'; 3 | import { expect } from 'chai'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('CompoundV3 ClaimLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.compoundv3.ClaimLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getClaimTokenList(chainId); 11 | expect(tokenList.length).to.eq(1); 12 | }); 13 | }); 14 | }); 15 | 16 | context('Test getQuotation', async function () { 17 | const chainId = common.ChainId.mainnet; 18 | 19 | const testCases: ClaimParams[] = [ 20 | { 21 | marketId: logics.compoundv3.MarketId.USDC, 22 | owner: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa', 23 | }, 24 | { 25 | marketId: logics.compoundv3.MarketId.ETH, 26 | owner: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa', 27 | }, 28 | ]; 29 | 30 | testCases.forEach((params, i) => { 31 | it(`case ${i + 1}`, async function () { 32 | const quotation = await getClaimQuotation(chainId, params); 33 | expect(quotation).to.include.all.keys('marketId', 'owner', 'output'); 34 | }); 35 | }); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /packages/api/src/protocols/compound-v3/claim.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type ClaimParams = common.Declasifying; 7 | 8 | export type ClaimFields = common.Declasifying; 9 | 10 | export type ClaimLogic = Logic; 11 | 12 | export async function getClaimTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.compoundv3.ClaimLogic.rid); 14 | } 15 | 16 | export async function getClaimQuotation( 17 | chainId: number, 18 | params: ClaimParams 19 | ): Promise { 20 | return quote(chainId, logics.compoundv3.ClaimLogic.rid, params); 21 | } 22 | 23 | export function newClaimLogic(fields: ClaimFields): ClaimLogic { 24 | return { rid: logics.compoundv3.ClaimLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/compound-v3/index.ts: -------------------------------------------------------------------------------- 1 | export * from './borrow'; 2 | export * from './claim'; 3 | export * from './repay'; 4 | export * from './supply-base'; 5 | export * from './supply-collateral'; 6 | export * from './withdraw-base'; 7 | export * from './withdraw-collateral'; 8 | -------------------------------------------------------------------------------- /packages/api/src/protocols/compound-v3/repay.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type RepayParams = common.Declasifying; 7 | 8 | export type RepayFields = common.Declasifying; 9 | 10 | export type RepayLogic = Logic; 11 | 12 | export async function getRepayTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.compoundv3.RepayLogic.rid); 14 | } 15 | 16 | export async function getRepayQuotation( 17 | chainId: number, 18 | params: RepayParams 19 | ): Promise { 20 | return quote(chainId, logics.compoundv3.RepayLogic.rid, params); 21 | } 22 | 23 | export function newRepayLogic(fields: RepayFields): RepayLogic { 24 | return { rid: logics.compoundv3.RepayLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/compound-v3/supply-base.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type SupplyBaseParams = common.Declasifying; 7 | 8 | export type SupplyBaseFields = common.Declasifying; 9 | 10 | export type SupplyBaseLogic = Logic; 11 | 12 | export async function getSupplyBaseTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.compoundv3.SupplyBaseLogic.rid); 14 | } 15 | 16 | export async function getSupplyBaseQuotation( 17 | chainId: number, 18 | params: SupplyBaseParams 19 | ): Promise { 20 | return quote(chainId, logics.compoundv3.SupplyBaseLogic.rid, params); 21 | } 22 | 23 | export function newSupplyBaseLogic(fields: SupplyBaseFields): SupplyBaseLogic { 24 | return { rid: logics.compoundv3.SupplyBaseLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/compound-v3/supply-collateral.test.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | import { expect } from 'chai'; 3 | import { getSupplyCollateralTokenList } from './supply-collateral'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('CompoundV3 SupplyCollateralLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.compoundv3.SupplyCollateralLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getSupplyCollateralTokenList(chainId); 11 | const marketIds = Object.keys(tokenList); 12 | expect(marketIds).to.have.lengthOf.above(0); 13 | for (const marketId of marketIds) { 14 | expect(tokenList[marketId]).to.have.lengthOf.above(0); 15 | } 16 | }); 17 | }); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /packages/api/src/protocols/compound-v3/supply-collateral.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type SupplyCollateralFields = common.Declasifying; 7 | 8 | export type SupplyCollateralLogic = Logic; 9 | 10 | export async function getSupplyCollateralTokenList( 11 | chainId: number 12 | ): Promise { 13 | return getProtocolTokenList(chainId, logics.compoundv3.SupplyCollateralLogic.rid); 14 | } 15 | 16 | export function newSupplyCollateralLogic(fields: SupplyCollateralFields): SupplyCollateralLogic { 17 | return { rid: logics.compoundv3.SupplyCollateralLogic.rid, fields }; 18 | } 19 | -------------------------------------------------------------------------------- /packages/api/src/protocols/compound-v3/withdraw-base.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type WithdrawBaseParams = common.Declasifying; 7 | 8 | export type WithdrawBaseFields = common.Declasifying; 9 | 10 | export type WithdrawBaseLogic = Logic; 11 | 12 | export async function getWithdrawBaseTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.compoundv3.WithdrawBaseLogic.rid); 14 | } 15 | 16 | export async function getWithdrawBaseQuotation( 17 | chainId: number, 18 | params: WithdrawBaseParams 19 | ): Promise { 20 | return quote(chainId, logics.compoundv3.WithdrawBaseLogic.rid, params); 21 | } 22 | 23 | export function newWithdrawBaseLogic(fields: WithdrawBaseFields): WithdrawBaseLogic { 24 | return { rid: logics.compoundv3.WithdrawBaseLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/compound-v3/withdraw-collateral.test.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | import { expect } from 'chai'; 3 | import { getWithdrawCollateralTokenList } from './withdraw-collateral'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('CompoundV3 WithdrawCollateralLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.compoundv3.WithdrawCollateralLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getWithdrawCollateralTokenList(chainId); 11 | const marketIds = Object.keys(tokenList); 12 | expect(marketIds).to.have.lengthOf.above(0); 13 | for (const marketId of marketIds) { 14 | expect(tokenList[marketId]).to.have.lengthOf.above(0); 15 | } 16 | }); 17 | }); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /packages/api/src/protocols/compound-v3/withdraw-collateral.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type WithdrawCollateralFields = common.Declasifying; 7 | 8 | export type WithdrawCollateralLogic = Logic; 9 | 10 | export async function getWithdrawCollateralTokenList( 11 | chainId: number 12 | ): Promise { 13 | return getProtocolTokenList(chainId, logics.compoundv3.WithdrawCollateralLogic.rid); 14 | } 15 | 16 | export function newWithdrawCollateralLogic(fields: WithdrawCollateralFields): WithdrawCollateralLogic { 17 | return { rid: logics.compoundv3.WithdrawCollateralLogic.rid, fields }; 18 | } 19 | -------------------------------------------------------------------------------- /packages/api/src/protocols/index.test.ts: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import fs from 'fs'; 3 | import path from 'path'; 4 | 5 | it('Test exports', async function () { 6 | const cwd = process.cwd(); 7 | const protocols = fs 8 | .readdirSync(path.join(cwd, 'src', 'protocols'), { withFileTypes: true }) 9 | .reduce((accumulator, dir) => { 10 | if (dir.isDirectory()) accumulator.push(dir.name); 11 | return accumulator; 12 | }, [] as string[]); 13 | 14 | const exports = await import('./index'); 15 | expect(Object.keys(exports)).to.include.members(protocols.map((protocol) => protocol.replace(/-/g, ''))); 16 | }); 17 | -------------------------------------------------------------------------------- /packages/api/src/protocols/index.ts: -------------------------------------------------------------------------------- 1 | export * as aavev2 from './aave-v2'; 2 | export * as aavev3 from './aave-v3'; 3 | export * as balancerv2 from './balancer-v2'; 4 | export * as compoundv3 from './compound-v3'; 5 | export * as iolend from './iolend'; 6 | export * as magicsea from './magicsea'; 7 | export * as morphoblue from './morphoblue'; 8 | export * as openoceanv2 from './openocean-v2'; 9 | export * as paraswapv5 from './paraswap-v5'; 10 | export * as permit2 from './permit2'; 11 | export * as radiantv2 from './radiant-v2'; 12 | export * as sonne from './sonne'; 13 | export * as spark from './spark'; 14 | export * as stargate from './stargate'; 15 | export * as stargatev2 from './stargate-v2'; 16 | export * as syncswap from './syncswap'; 17 | export * as uniswapv3 from './uniswap-v3'; 18 | export * as utility from './utility'; 19 | export * as wagmi from './wagmi'; 20 | export * as zeroexv4 from './zeroex-v4'; 21 | -------------------------------------------------------------------------------- /packages/api/src/protocols/iolend/borrow.test.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | import { expect } from 'chai'; 3 | import { getBorrowTokenList } from './borrow'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('Iolend BorrowLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.iolend.BorrowLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getBorrowTokenList(chainId); 11 | expect(tokenList).to.have.lengthOf.above(0); 12 | }); 13 | }); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /packages/api/src/protocols/iolend/borrow.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type BorrowFields = common.Declasifying; 7 | 8 | export type BorrowLogic = Logic; 9 | 10 | export async function getBorrowTokenList(chainId: number): Promise { 11 | return getProtocolTokenList(chainId, logics.iolend.BorrowLogic.rid); 12 | } 13 | 14 | export function newBorrowLogic(fields: BorrowFields): BorrowLogic { 15 | return { rid: logics.iolend.BorrowLogic.rid, fields }; 16 | } 17 | -------------------------------------------------------------------------------- /packages/api/src/protocols/iolend/deposit.test.ts: -------------------------------------------------------------------------------- 1 | import { DepositParams, getDepositQuotation, getDepositTokenList } from './deposit'; 2 | import * as common from '@protocolink/common'; 3 | import { expect } from 'chai'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('Iolend DepositLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.iolend.DepositLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getDepositTokenList(chainId); 11 | expect(tokenList).to.have.lengthOf.above(0); 12 | }); 13 | }); 14 | }); 15 | 16 | context('Test getQuotation', async function () { 17 | const chainId = common.ChainId.iota; 18 | 19 | const testCases: DepositParams[] = [ 20 | { 21 | input: { token: common.iotaTokens.IOTA, amount: '1' }, 22 | tokenOut: logics.iolend.iotaTokens.iWIOTA, 23 | }, 24 | { 25 | input: { token: common.iotaTokens.USDT, amount: '1' }, 26 | tokenOut: logics.iolend.iotaTokens.iUSDT, 27 | }, 28 | ]; 29 | 30 | testCases.forEach((params, i) => { 31 | it(`case ${i + 1}`, async function () { 32 | const quotation = await getDepositQuotation(chainId, params); 33 | expect(quotation).to.include.all.keys('input', 'output'); 34 | }); 35 | }); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /packages/api/src/protocols/iolend/deposit.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type DepositParams = common.Declasifying; 7 | 8 | export type DepositFields = common.Declasifying; 9 | 10 | export type DepositLogic = Logic; 11 | 12 | export async function getDepositTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.iolend.DepositLogic.rid); 14 | } 15 | 16 | export async function getDepositQuotation( 17 | chainId: number, 18 | params: DepositParams 19 | ): Promise { 20 | return quote(chainId, logics.iolend.DepositLogic.rid, params); 21 | } 22 | 23 | export function newDepositLogic(fields: DepositFields): DepositLogic { 24 | return { rid: logics.iolend.DepositLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/iolend/index.ts: -------------------------------------------------------------------------------- 1 | export * from './borrow'; 2 | export * from './deposit'; 3 | export * from './repay'; 4 | export * from './withdraw'; 5 | -------------------------------------------------------------------------------- /packages/api/src/protocols/iolend/repay.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type RepayParams = common.Declasifying; 7 | 8 | export type RepayFields = common.Declasifying; 9 | 10 | export type RepayLogic = Logic; 11 | 12 | export async function getRepayTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.iolend.RepayLogic.rid); 14 | } 15 | 16 | export async function getRepayQuotation(chainId: number, params: RepayParams): Promise { 17 | return quote(chainId, logics.iolend.RepayLogic.rid, params); 18 | } 19 | 20 | export function newRepayLogic(fields: RepayFields): RepayLogic { 21 | return { rid: logics.iolend.RepayLogic.rid, fields }; 22 | } 23 | -------------------------------------------------------------------------------- /packages/api/src/protocols/iolend/withdraw.test.ts: -------------------------------------------------------------------------------- 1 | import { WithdrawParams, getWithdrawQuotation, getWithdrawTokenList } from './withdraw'; 2 | import * as common from '@protocolink/common'; 3 | import { expect } from 'chai'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('Iolend WithdrawLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.iolend.WithdrawLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getWithdrawTokenList(chainId); 11 | expect(tokenList).to.have.lengthOf.above(0); 12 | }); 13 | }); 14 | }); 15 | 16 | context('Test getQuotation', async function () { 17 | const chainId = common.ChainId.iota; 18 | 19 | const testCases: WithdrawParams[] = [ 20 | { 21 | input: { token: logics.iolend.iotaTokens.iWIOTA, amount: '1' }, 22 | tokenOut: common.iotaTokens.IOTA, 23 | }, 24 | { 25 | input: { token: logics.iolend.iotaTokens.iUSDT, amount: '1' }, 26 | tokenOut: common.iotaTokens.USDT, 27 | }, 28 | ]; 29 | 30 | testCases.forEach((params, i) => { 31 | it(`case ${i + 1}`, async function () { 32 | const quotation = await getWithdrawQuotation(chainId, params); 33 | expect(quotation).to.include.all.keys('input', 'output'); 34 | }); 35 | }); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /packages/api/src/protocols/iolend/withdraw.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type WithdrawParams = common.Declasifying; 7 | 8 | export type WithdrawFields = common.Declasifying; 9 | 10 | export type WithdrawLogic = Logic; 11 | 12 | export async function getWithdrawTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.iolend.WithdrawLogic.rid); 14 | } 15 | 16 | export async function getWithdrawQuotation( 17 | chainId: number, 18 | params: WithdrawParams 19 | ): Promise { 20 | return quote(chainId, logics.iolend.WithdrawLogic.rid, params); 21 | } 22 | 23 | export function newWithdrawLogic(fields: WithdrawFields): WithdrawLogic { 24 | return { rid: logics.iolend.WithdrawLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/magicsea/index.ts: -------------------------------------------------------------------------------- 1 | export * from './swap-token'; 2 | -------------------------------------------------------------------------------- /packages/api/src/protocols/magicsea/swap-token.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type SwapTokenParams = common.Declasifying; 7 | 8 | export type SwapTokenFields = common.Declasifying; 9 | 10 | export type SwapTokenLogic = Logic; 11 | 12 | export async function getSwapTokenTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.magicsea.SwapTokenLogic.rid); 14 | } 15 | 16 | export async function getSwapTokenQuotation( 17 | chainId: number, 18 | params: SwapTokenParams 19 | ): Promise { 20 | return quote(chainId, logics.magicsea.SwapTokenLogic.rid, params); 21 | } 22 | 23 | export function newSwapTokenLogic(fields: SwapTokenFields): SwapTokenLogic { 24 | return { rid: logics.magicsea.SwapTokenLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/morphoblue/borrow.test.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | import { expect } from 'chai'; 3 | import { getBorrowTokenList } from './borrow'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('Morphoblue BorrowLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.morphoblue.BorrowLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getBorrowTokenList(chainId); 11 | const marketIds = Object.keys(tokenList); 12 | expect(marketIds).to.have.lengthOf.above(0); 13 | for (const marketId of marketIds) { 14 | expect(tokenList[marketId]).to.have.lengthOf.above(0); 15 | } 16 | }); 17 | }); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /packages/api/src/protocols/morphoblue/borrow.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type BorrowFields = common.Declasifying; 7 | 8 | export type BorrowLogic = Logic; 9 | 10 | export async function getBorrowTokenList(chainId: number): Promise { 11 | return getProtocolTokenList(chainId, logics.morphoblue.BorrowLogic.rid); 12 | } 13 | 14 | export function newBorrowLogic(fields: BorrowFields): BorrowLogic { 15 | return { rid: logics.morphoblue.BorrowLogic.rid, fields }; 16 | } 17 | -------------------------------------------------------------------------------- /packages/api/src/protocols/morphoblue/flash-loan.ts: -------------------------------------------------------------------------------- 1 | import { FlashLoanFields, FlashLoanLogic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | import { v4 as uuid } from 'uuid'; 6 | 7 | export type FlashLoanParams = common.Declasifying; 8 | 9 | export async function getFlashLoanTokenList(chainId: number): Promise { 10 | return getProtocolTokenList(chainId, logics.morphoblue.FlashLoanLogic.rid); 11 | } 12 | 13 | export async function getFlashLoanQuotation( 14 | chainId: number, 15 | params: FlashLoanParams 16 | ): Promise { 17 | return quote(chainId, logics.morphoblue.FlashLoanLogic.rid, params); 18 | } 19 | 20 | export function newFlashLoanLogic(fields: FlashLoanFields): FlashLoanLogic { 21 | return { rid: logics.morphoblue.FlashLoanLogic.rid, fields }; 22 | } 23 | 24 | export function newFlashLoanLogicPair(loans: FlashLoanFields['loans']): [FlashLoanLogic, FlashLoanLogic] { 25 | const id = uuid(); 26 | return [newFlashLoanLogic({ id, loans, isLoan: true }), newFlashLoanLogic({ id, loans, isLoan: false })]; 27 | } 28 | -------------------------------------------------------------------------------- /packages/api/src/protocols/morphoblue/index.ts: -------------------------------------------------------------------------------- 1 | export * from './borrow'; 2 | export * from './flash-loan'; 3 | export * from './repay'; 4 | export * from './supply-collateral'; 5 | export * from './supply'; 6 | export * from './withdraw-collateral'; 7 | export * from './withdraw'; 8 | -------------------------------------------------------------------------------- /packages/api/src/protocols/morphoblue/repay.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type RepayParams = common.Declasifying; 7 | 8 | export type RepayFields = common.Declasifying; 9 | 10 | export type RepayLogic = Logic; 11 | 12 | export async function getRepayTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.morphoblue.RepayLogic.rid); 14 | } 15 | 16 | export async function getRepayQuotation( 17 | chainId: number, 18 | params: RepayParams 19 | ): Promise { 20 | return quote(chainId, logics.morphoblue.RepayLogic.rid, params); 21 | } 22 | 23 | export function newRepayLogic(fields: RepayFields): RepayLogic { 24 | return { rid: logics.morphoblue.RepayLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/morphoblue/supply-collateral.test.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | import { expect } from 'chai'; 3 | import { getSupplyCollateralTokenList } from './supply-collateral'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('Morpho SupplyCollateralLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.morphoblue.SupplyCollateralLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getSupplyCollateralTokenList(chainId); 11 | const marketIds = Object.keys(tokenList); 12 | expect(marketIds).to.have.lengthOf.above(0); 13 | for (const marketId of marketIds) { 14 | expect(tokenList[marketId]).to.have.lengthOf.above(0); 15 | } 16 | }); 17 | }); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /packages/api/src/protocols/morphoblue/supply-collateral.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type SupplyCollateralFields = common.Declasifying; 7 | 8 | export type SupplyCollateralLogic = Logic; 9 | 10 | export async function getSupplyCollateralTokenList( 11 | chainId: number 12 | ): Promise { 13 | return getProtocolTokenList(chainId, logics.morphoblue.SupplyCollateralLogic.rid); 14 | } 15 | 16 | export function newSupplyCollateralLogic(fields: SupplyCollateralFields): SupplyCollateralLogic { 17 | return { rid: logics.morphoblue.SupplyCollateralLogic.rid, fields }; 18 | } 19 | -------------------------------------------------------------------------------- /packages/api/src/protocols/morphoblue/supply.test.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | import { expect } from 'chai'; 3 | import { getSupplyTokenList } from './supply'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('Morpho SupplyLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.morphoblue.SupplyLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getSupplyTokenList(chainId); 11 | const marketIds = Object.keys(tokenList); 12 | expect(marketIds).to.have.lengthOf.above(0); 13 | for (const marketId of marketIds) { 14 | expect(tokenList[marketId]).to.have.lengthOf.above(0); 15 | } 16 | }); 17 | }); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /packages/api/src/protocols/morphoblue/supply.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type SupplyFields = common.Declasifying; 7 | 8 | export type SupplyLogic = Logic; 9 | 10 | export async function getSupplyTokenList(chainId: number): Promise { 11 | return getProtocolTokenList(chainId, logics.morphoblue.SupplyLogic.rid); 12 | } 13 | 14 | export function newSupplyLogic(fields: SupplyFields): SupplyLogic { 15 | return { rid: logics.morphoblue.SupplyLogic.rid, fields }; 16 | } 17 | -------------------------------------------------------------------------------- /packages/api/src/protocols/morphoblue/withdraw-collateral.test.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | import { expect } from 'chai'; 3 | import { getWithdrawCollateralTokenList } from './withdraw-collateral'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('Morpho WithdrawCollateralLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.morphoblue.WithdrawCollateralLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getWithdrawCollateralTokenList(chainId); 11 | const marketIds = Object.keys(tokenList); 12 | expect(marketIds).to.have.lengthOf.above(0); 13 | for (const marketId of marketIds) { 14 | expect(tokenList[marketId]).to.have.lengthOf.above(0); 15 | } 16 | }); 17 | }); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /packages/api/src/protocols/morphoblue/withdraw-collateral.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type WithdrawCollateralFields = common.Declasifying; 7 | 8 | export type WithdrawCollateralLogic = Logic; 9 | 10 | export async function getWithdrawCollateralTokenList( 11 | chainId: number 12 | ): Promise { 13 | return getProtocolTokenList(chainId, logics.morphoblue.WithdrawCollateralLogic.rid); 14 | } 15 | 16 | export function newWithdrawCollateralLogic(fields: WithdrawCollateralFields): WithdrawCollateralLogic { 17 | return { rid: logics.morphoblue.WithdrawCollateralLogic.rid, fields }; 18 | } 19 | -------------------------------------------------------------------------------- /packages/api/src/protocols/morphoblue/withdraw.test.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | import { expect } from 'chai'; 3 | import { getWithdrawTokenList } from './withdraw'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('Morpho WithdrawLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.morphoblue.WithdrawLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getWithdrawTokenList(chainId); 11 | const marketIds = Object.keys(tokenList); 12 | expect(marketIds).to.have.lengthOf.above(0); 13 | for (const marketId of marketIds) { 14 | expect(tokenList[marketId]).to.have.lengthOf.above(0); 15 | } 16 | }); 17 | }); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /packages/api/src/protocols/morphoblue/withdraw.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type WithdrawFields = common.Declasifying; 7 | 8 | export type WithdrawLogic = Logic; 9 | 10 | export async function getWithdrawTokenList(chainId: number): Promise { 11 | return getProtocolTokenList(chainId, logics.morphoblue.WithdrawLogic.rid); 12 | } 13 | 14 | export function newWithdrawLogic(fields: WithdrawFields): WithdrawLogic { 15 | return { rid: logics.morphoblue.WithdrawLogic.rid, fields }; 16 | } 17 | -------------------------------------------------------------------------------- /packages/api/src/protocols/openocean-v2/index.ts: -------------------------------------------------------------------------------- 1 | export * from './swap-token'; 2 | -------------------------------------------------------------------------------- /packages/api/src/protocols/openocean-v2/swap-token.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type SwapTokenParams = common.Declasifying; 7 | 8 | export type SwapTokenFields = common.Declasifying; 9 | 10 | export type SwapTokenLogic = Logic; 11 | 12 | export async function getSwapTokenTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.openoceanv2.SwapTokenLogic.rid); 14 | } 15 | 16 | export async function getSwapTokenQuotation( 17 | chainId: number, 18 | params: SwapTokenParams 19 | ): Promise { 20 | return quote(chainId, logics.openoceanv2.SwapTokenLogic.rid, params); 21 | } 22 | 23 | export function newSwapTokenLogic(fields: SwapTokenFields): SwapTokenLogic { 24 | return { rid: logics.openoceanv2.SwapTokenLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/paraswap-v5/index.ts: -------------------------------------------------------------------------------- 1 | export * from './swap-token'; 2 | -------------------------------------------------------------------------------- /packages/api/src/protocols/paraswap-v5/swap-token.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type SwapTokenParams = common.Declasifying; 7 | 8 | export type SwapTokenFields = common.Declasifying; 9 | 10 | export type SwapTokenLogic = Logic; 11 | 12 | export async function getSwapTokenTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.paraswapv5.SwapTokenLogic.rid); 14 | } 15 | 16 | export async function getSwapTokenQuotation( 17 | chainId: number, 18 | params: SwapTokenParams 19 | ): Promise { 20 | return quote(chainId, logics.paraswapv5.SwapTokenLogic.rid, params); 21 | } 22 | 23 | export function newSwapTokenLogic(fields: SwapTokenFields): SwapTokenLogic { 24 | return { rid: logics.paraswapv5.SwapTokenLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/permit2/index.ts: -------------------------------------------------------------------------------- 1 | export * from './pull-token'; 2 | -------------------------------------------------------------------------------- /packages/api/src/protocols/permit2/pull-token.test.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | import { expect } from 'chai'; 3 | import { getPullTokenTokenList } from './pull-token'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('Permit2 PullTokenLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.permit2.PullTokenLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getPullTokenTokenList(chainId); 11 | expect(tokenList).to.have.lengthOf.above(0); 12 | }); 13 | }); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /packages/api/src/protocols/permit2/pull-token.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type PullTokenFields = common.Declasifying; 7 | 8 | export type PullTokenLogic = Logic; 9 | 10 | export async function getPullTokenTokenList(chainId: number): Promise { 11 | return getProtocolTokenList(chainId, logics.permit2.PullTokenLogic.rid); 12 | } 13 | 14 | export function newPullTokenLogic(fields: PullTokenFields): PullTokenLogic { 15 | return { rid: logics.permit2.PullTokenLogic.rid, fields }; 16 | } 17 | -------------------------------------------------------------------------------- /packages/api/src/protocols/radiant-v2/borrow.test.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | import { expect } from 'chai'; 3 | import { getBorrowTokenList } from './borrow'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('RadiantV2 BorrowLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.radiantv2.BorrowLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getBorrowTokenList(chainId); 11 | expect(tokenList).to.have.lengthOf.above(0); 12 | }); 13 | }); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /packages/api/src/protocols/radiant-v2/borrow.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type BorrowFields = common.Declasifying; 7 | 8 | export type BorrowLogic = Logic; 9 | 10 | export async function getBorrowTokenList(chainId: number): Promise { 11 | return getProtocolTokenList(chainId, logics.radiantv2.BorrowLogic.rid); 12 | } 13 | 14 | export function newBorrowLogic(fields: BorrowFields): BorrowLogic { 15 | return { rid: logics.radiantv2.BorrowLogic.rid, fields }; 16 | } 17 | -------------------------------------------------------------------------------- /packages/api/src/protocols/radiant-v2/deposit.test.ts: -------------------------------------------------------------------------------- 1 | import { DepositParams, getDepositQuotation, getDepositTokenList } from './deposit'; 2 | import * as common from '@protocolink/common'; 3 | import { expect } from 'chai'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('RadiantV2 DepositLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.radiantv2.DepositLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getDepositTokenList(chainId); 11 | expect(tokenList).to.have.lengthOf.above(0); 12 | }); 13 | }); 14 | }); 15 | 16 | context('Test getQuotation', async function () { 17 | const chainId = common.ChainId.mainnet; 18 | 19 | const testCases: DepositParams[] = [ 20 | { 21 | input: { token: common.mainnetTokens.ETH, amount: '1' }, 22 | tokenOut: logics.radiantv2.mainnetTokens.rWETH, 23 | }, 24 | { 25 | input: { token: common.mainnetTokens.USDC, amount: '1' }, 26 | tokenOut: logics.radiantv2.mainnetTokens.rUSDC, 27 | }, 28 | ]; 29 | 30 | testCases.forEach((params, i) => { 31 | it(`case ${i + 1}`, async function () { 32 | const quotation = await getDepositQuotation(chainId, params); 33 | expect(quotation).to.include.all.keys('input', 'output'); 34 | }); 35 | }); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /packages/api/src/protocols/radiant-v2/deposit.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type DepositParams = common.Declasifying; 7 | 8 | export type DepositFields = common.Declasifying; 9 | 10 | export type DepositLogic = Logic; 11 | 12 | export async function getDepositTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.radiantv2.DepositLogic.rid); 14 | } 15 | 16 | export async function getDepositQuotation( 17 | chainId: number, 18 | params: DepositParams 19 | ): Promise { 20 | return quote(chainId, logics.radiantv2.DepositLogic.rid, params); 21 | } 22 | 23 | export function newDepositLogic(fields: DepositFields): DepositLogic { 24 | return { rid: logics.radiantv2.DepositLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/radiant-v2/flash-loan.ts: -------------------------------------------------------------------------------- 1 | import { FlashLoanFields, FlashLoanLogic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | import { v4 as uuid } from 'uuid'; 6 | 7 | export type FlashLoanParams = common.Declasifying; 8 | 9 | export async function getFlashLoanTokenList(chainId: number): Promise { 10 | return getProtocolTokenList(chainId, logics.radiantv2.FlashLoanLogic.rid); 11 | } 12 | 13 | export async function getFlashLoanQuotation( 14 | chainId: number, 15 | params: FlashLoanParams 16 | ): Promise { 17 | return quote(chainId, logics.radiantv2.FlashLoanLogic.rid, params); 18 | } 19 | 20 | export function newFlashLoanLogic(fields: FlashLoanFields): FlashLoanLogic { 21 | return { rid: logics.radiantv2.FlashLoanLogic.rid, fields }; 22 | } 23 | 24 | export function newFlashLoanLogicPair(loans: FlashLoanFields['loans']): [FlashLoanLogic, FlashLoanLogic] { 25 | const id = uuid(); 26 | return [newFlashLoanLogic({ id, loans, isLoan: true }), newFlashLoanLogic({ id, loans, isLoan: false })]; 27 | } 28 | -------------------------------------------------------------------------------- /packages/api/src/protocols/radiant-v2/index.ts: -------------------------------------------------------------------------------- 1 | export * from './borrow'; 2 | export * from './deposit'; 3 | export * from './flash-loan'; 4 | export * from './repay'; 5 | export * from './withdraw'; 6 | -------------------------------------------------------------------------------- /packages/api/src/protocols/radiant-v2/repay.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type RepayParams = common.Declasifying; 7 | 8 | export type RepayFields = common.Declasifying; 9 | 10 | export type RepayLogic = Logic; 11 | 12 | export async function getRepayTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.radiantv2.RepayLogic.rid); 14 | } 15 | 16 | export async function getRepayQuotation( 17 | chainId: number, 18 | params: RepayParams 19 | ): Promise { 20 | return quote(chainId, logics.radiantv2.RepayLogic.rid, params); 21 | } 22 | 23 | export function newRepayLogic(fields: RepayFields): RepayLogic { 24 | return { rid: logics.radiantv2.RepayLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/radiant-v2/withdraw.test.ts: -------------------------------------------------------------------------------- 1 | import { WithdrawParams, getWithdrawQuotation, getWithdrawTokenList } from './withdraw'; 2 | import * as common from '@protocolink/common'; 3 | import { expect } from 'chai'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('RadiantV2 WithdrawLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.radiantv2.WithdrawLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getWithdrawTokenList(chainId); 11 | expect(tokenList).to.have.lengthOf.above(0); 12 | }); 13 | }); 14 | }); 15 | 16 | context('Test getQuotation', async function () { 17 | const chainId = common.ChainId.mainnet; 18 | 19 | const testCases: WithdrawParams[] = [ 20 | { 21 | input: { token: logics.radiantv2.mainnetTokens.rWETH, amount: '1' }, 22 | tokenOut: common.mainnetTokens.ETH, 23 | }, 24 | { 25 | input: { token: logics.radiantv2.mainnetTokens.rUSDC, amount: '1' }, 26 | tokenOut: common.mainnetTokens.USDC, 27 | }, 28 | ]; 29 | 30 | testCases.forEach((params, i) => { 31 | it(`case ${i + 1}`, async function () { 32 | const quotation = await getWithdrawQuotation(chainId, params); 33 | expect(quotation).to.include.all.keys('input', 'output'); 34 | }); 35 | }); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /packages/api/src/protocols/radiant-v2/withdraw.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type WithdrawParams = common.Declasifying; 7 | 8 | export type WithdrawFields = common.Declasifying; 9 | 10 | export type WithdrawLogic = Logic; 11 | 12 | export async function getWithdrawTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.radiantv2.WithdrawLogic.rid); 14 | } 15 | 16 | export async function getWithdrawQuotation( 17 | chainId: number, 18 | params: WithdrawParams 19 | ): Promise { 20 | return quote(chainId, logics.radiantv2.WithdrawLogic.rid, params); 21 | } 22 | 23 | export function newWithdrawLogic(fields: WithdrawFields): WithdrawLogic { 24 | return { rid: logics.radiantv2.WithdrawLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/sonne/borrow.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type BorrowFields = common.Declasifying; 7 | 8 | export type BorrowLogic = Logic; 9 | 10 | export async function getBorrowTokenList(chainId: number): Promise { 11 | return getProtocolTokenList(chainId, logics.sonne.BorrowLogic.rid); 12 | } 13 | 14 | export function newBorrowLogic(fields: BorrowFields): BorrowLogic { 15 | return { rid: logics.sonne.BorrowLogic.rid, fields }; 16 | } 17 | -------------------------------------------------------------------------------- /packages/api/src/protocols/sonne/index.ts: -------------------------------------------------------------------------------- 1 | export * from './borrow'; 2 | export * from './supply'; 3 | export * from './repay'; 4 | export * from './withdraw'; 5 | -------------------------------------------------------------------------------- /packages/api/src/protocols/sonne/repay.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type RepayParams = common.Declasifying; 7 | 8 | export type RepayFields = common.Declasifying; 9 | 10 | export type RepayLogic = Logic; 11 | 12 | export async function getRepayTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.sonne.RepayLogic.rid); 14 | } 15 | 16 | export async function getRepayQuotation(chainId: number, params: RepayParams): Promise { 17 | return quote(chainId, logics.sonne.RepayLogic.rid, params); 18 | } 19 | 20 | export function newRepayLogic(fields: RepayFields): RepayLogic { 21 | return { rid: logics.sonne.RepayLogic.rid, fields }; 22 | } 23 | -------------------------------------------------------------------------------- /packages/api/src/protocols/sonne/supply.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type SupplyParams = common.Declasifying; 7 | 8 | export type SupplyFields = common.Declasifying; 9 | 10 | export type SupplyLogic = Logic; 11 | 12 | export async function getSupplyTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.sonne.SupplyLogic.rid); 14 | } 15 | 16 | export async function getSupplyQuotation( 17 | chainId: number, 18 | params: SupplyParams 19 | ): Promise { 20 | return quote(chainId, logics.sonne.SupplyLogic.rid, params); 21 | } 22 | 23 | export function newSupplyLogic(fields: SupplyFields): SupplyLogic { 24 | return { rid: logics.sonne.SupplyLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/sonne/withdraw.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type WithdrawParams = common.Declasifying; 7 | 8 | export type WithdrawFields = common.Declasifying; 9 | 10 | export type WithdrawLogic = Logic; 11 | 12 | export async function getWithdrawTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.sonne.WithdrawLogic.rid); 14 | } 15 | 16 | export async function getWithdrawQuotation( 17 | chainId: number, 18 | params: WithdrawParams 19 | ): Promise { 20 | return quote(chainId, logics.sonne.WithdrawLogic.rid, params); 21 | } 22 | 23 | export function newWithdrawLogic(fields: WithdrawFields): WithdrawLogic { 24 | return { rid: logics.sonne.WithdrawLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/spark/borrow.test.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | import { expect } from 'chai'; 3 | import { getBorrowTokenList } from './borrow'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('Spark BorrowLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.spark.BorrowLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getBorrowTokenList(chainId); 11 | expect(tokenList).to.have.lengthOf.above(0); 12 | }); 13 | }); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /packages/api/src/protocols/spark/borrow.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type BorrowFields = common.Declasifying; 7 | 8 | export type BorrowLogic = Logic; 9 | 10 | export async function getBorrowTokenList(chainId: number): Promise { 11 | return getProtocolTokenList(chainId, logics.spark.BorrowLogic.rid); 12 | } 13 | 14 | export function newBorrowLogic(fields: BorrowFields): BorrowLogic { 15 | return { rid: logics.spark.BorrowLogic.rid, fields }; 16 | } 17 | -------------------------------------------------------------------------------- /packages/api/src/protocols/spark/flash-loan.ts: -------------------------------------------------------------------------------- 1 | import { FlashLoanFields, FlashLoanLogic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | import { v4 as uuid } from 'uuid'; 6 | 7 | export type FlashLoanParams = common.Declasifying; 8 | 9 | export async function getFlashLoanTokenList(chainId: number): Promise { 10 | return getProtocolTokenList(chainId, logics.spark.FlashLoanLogic.rid); 11 | } 12 | 13 | export async function getFlashLoanQuotation( 14 | chainId: number, 15 | params: FlashLoanParams 16 | ): Promise { 17 | return quote(chainId, logics.spark.FlashLoanLogic.rid, params); 18 | } 19 | 20 | export function newFlashLoanLogic(fields: FlashLoanFields): FlashLoanLogic { 21 | return { rid: logics.spark.FlashLoanLogic.rid, fields }; 22 | } 23 | 24 | export function newFlashLoanLogicPair(loans: FlashLoanFields['loans']): [FlashLoanLogic, FlashLoanLogic] { 25 | const id = uuid(); 26 | return [newFlashLoanLogic({ id, loans, isLoan: true }), newFlashLoanLogic({ id, loans, isLoan: false })]; 27 | } 28 | -------------------------------------------------------------------------------- /packages/api/src/protocols/spark/index.ts: -------------------------------------------------------------------------------- 1 | export * from './borrow'; 2 | export * from './supply'; 3 | export * from './flash-loan'; 4 | export * from './repay'; 5 | export * from './withdraw'; 6 | -------------------------------------------------------------------------------- /packages/api/src/protocols/spark/repay.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type RepayParams = common.Declasifying; 7 | 8 | export type RepayFields = common.Declasifying; 9 | 10 | export type RepayLogic = Logic; 11 | 12 | export async function getRepayTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.spark.RepayLogic.rid); 14 | } 15 | 16 | export async function getRepayQuotation(chainId: number, params: RepayParams): Promise { 17 | return quote(chainId, logics.spark.RepayLogic.rid, params); 18 | } 19 | 20 | export function newRepayLogic(fields: RepayFields): RepayLogic { 21 | return { rid: logics.spark.RepayLogic.rid, fields }; 22 | } 23 | -------------------------------------------------------------------------------- /packages/api/src/protocols/spark/supply.test.ts: -------------------------------------------------------------------------------- 1 | import { SupplyParams, getSupplyQuotation, getSupplyTokenList } from './supply'; 2 | import * as common from '@protocolink/common'; 3 | import { expect } from 'chai'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('Spark SupplyLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.spark.SupplyLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getSupplyTokenList(chainId); 11 | expect(tokenList).to.have.lengthOf.above(0); 12 | }); 13 | }); 14 | }); 15 | 16 | context('Test getQuotation', async function () { 17 | const chainId = common.ChainId.mainnet; 18 | 19 | const testCases: SupplyParams[] = [ 20 | { 21 | input: { token: logics.spark.mainnetTokens.ETH, amount: '1' }, 22 | tokenOut: logics.spark.mainnetTokens.spWETH, 23 | }, 24 | { 25 | input: { token: logics.spark.mainnetTokens.USDC, amount: '1' }, 26 | tokenOut: logics.spark.mainnetTokens.spUSDC, 27 | }, 28 | ]; 29 | 30 | testCases.forEach((params, i) => { 31 | it(`case ${i + 1}`, async function () { 32 | const quotation = await getSupplyQuotation(chainId, params); 33 | expect(quotation).to.include.all.keys('input', 'output'); 34 | }); 35 | }); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /packages/api/src/protocols/spark/supply.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type SupplyParams = common.Declasifying; 7 | 8 | export type SupplyFields = common.Declasifying; 9 | 10 | export type SupplyLogic = Logic; 11 | 12 | export async function getSupplyTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.spark.SupplyLogic.rid); 14 | } 15 | 16 | export async function getSupplyQuotation( 17 | chainId: number, 18 | params: SupplyParams 19 | ): Promise { 20 | return quote(chainId, logics.spark.SupplyLogic.rid, params); 21 | } 22 | 23 | export function newSupplyLogic(fields: SupplyFields): SupplyLogic { 24 | return { rid: logics.spark.SupplyLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/spark/withdraw.test.ts: -------------------------------------------------------------------------------- 1 | import { WithdrawParams, getWithdrawQuotation, getWithdrawTokenList } from './withdraw'; 2 | import * as common from '@protocolink/common'; 3 | import { expect } from 'chai'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('Spark WithdrawLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.spark.WithdrawLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getWithdrawTokenList(chainId); 11 | expect(tokenList).to.have.lengthOf.above(0); 12 | }); 13 | }); 14 | }); 15 | 16 | context('Test getQuotation', async function () { 17 | const chainId = common.ChainId.mainnet; 18 | 19 | const testCases: WithdrawParams[] = [ 20 | { 21 | input: { token: logics.spark.mainnetTokens.spWETH, amount: '1' }, 22 | tokenOut: logics.spark.mainnetTokens.ETH, 23 | }, 24 | { 25 | input: { token: logics.spark.mainnetTokens.spUSDC, amount: '1' }, 26 | tokenOut: logics.spark.mainnetTokens.USDC, 27 | }, 28 | ]; 29 | 30 | testCases.forEach((params, i) => { 31 | it(`case ${i + 1}`, async function () { 32 | const quotation = await getWithdrawQuotation(chainId, params); 33 | expect(quotation).to.include.all.keys('input', 'output'); 34 | }); 35 | }); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /packages/api/src/protocols/spark/withdraw.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type WithdrawParams = common.Declasifying; 7 | 8 | export type WithdrawFields = common.Declasifying; 9 | 10 | export type WithdrawLogic = Logic; 11 | 12 | export async function getWithdrawTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.spark.WithdrawLogic.rid); 14 | } 15 | 16 | export async function getWithdrawQuotation( 17 | chainId: number, 18 | params: WithdrawParams 19 | ): Promise { 20 | return quote(chainId, logics.spark.WithdrawLogic.rid, params); 21 | } 22 | 23 | export function newWithdrawLogic(fields: WithdrawFields): WithdrawLogic { 24 | return { rid: logics.spark.WithdrawLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/stargate-v2/index.ts: -------------------------------------------------------------------------------- 1 | export * from './swap-token'; 2 | -------------------------------------------------------------------------------- /packages/api/src/protocols/stargate-v2/swap-token.test.ts: -------------------------------------------------------------------------------- 1 | import { SwapTokenParams, getSwapTokenQuotation, getSwapTokenTokenList } from './swap-token'; 2 | import * as common from '@protocolink/common'; 3 | import { expect } from 'chai'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('StargateV2 SwapTokenLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.stargatev2.SwapTokenLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getSwapTokenTokenList(chainId); 11 | expect(tokenList).to.have.lengthOf.above(0); 12 | }); 13 | }); 14 | }); 15 | 16 | context('Test getQuotation', async function () { 17 | const chainId = common.ChainId.bnb; 18 | 19 | const testCases: SwapTokenParams[] = [ 20 | { 21 | input: { token: common.bnbTokens.Cake, amount: '1' }, 22 | tokenOut: common.polygonZkevmTokens.Cake, 23 | receiver: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa', 24 | }, 25 | ]; 26 | 27 | testCases.forEach((params, i) => { 28 | it(`case ${i + 1}`, async function () { 29 | const quotation = await getSwapTokenQuotation(chainId, params); 30 | expect(quotation).to.include.all.keys('input', 'output', 'fee', 'oftFee', 'receiver'); 31 | }); 32 | }); 33 | }); 34 | }); 35 | -------------------------------------------------------------------------------- /packages/api/src/protocols/stargate-v2/swap-token.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type SwapTokenParams = common.Declasifying; 7 | 8 | export type SwapTokenFields = common.Declasifying; 9 | 10 | export type SwapTokenLogic = Logic; 11 | 12 | export async function getSwapTokenTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.stargatev2.SwapTokenLogic.rid); 14 | } 15 | 16 | export async function getSwapTokenQuotation( 17 | chainId: number, 18 | params: SwapTokenParams 19 | ): Promise { 20 | return quote(chainId, logics.stargatev2.SwapTokenLogic.rid, params); 21 | } 22 | 23 | export function newSwapTokenLogic(fields: SwapTokenFields): SwapTokenLogic { 24 | return { rid: logics.stargatev2.SwapTokenLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/stargate/index.ts: -------------------------------------------------------------------------------- 1 | export * from './swap-token'; 2 | -------------------------------------------------------------------------------- /packages/api/src/protocols/stargate/swap-token.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type SwapTokenParams = common.Declasifying; 7 | 8 | export type SwapTokenFields = common.Declasifying; 9 | 10 | export type SwapTokenLogic = Logic; 11 | 12 | export async function getSwapTokenTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.stargate.SwapTokenLogic.rid); 14 | } 15 | 16 | export async function getSwapTokenQuotation( 17 | chainId: number, 18 | params: SwapTokenParams 19 | ): Promise { 20 | return quote(chainId, logics.stargate.SwapTokenLogic.rid, params); 21 | } 22 | 23 | export function newSwapTokenLogic(fields: SwapTokenFields): SwapTokenLogic { 24 | return { rid: logics.stargate.SwapTokenLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/syncswap/index.ts: -------------------------------------------------------------------------------- 1 | export * from './swap-token'; 2 | -------------------------------------------------------------------------------- /packages/api/src/protocols/syncswap/swap-token.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type SwapTokenParams = common.Declasifying; 7 | 8 | export type SwapTokenFields = common.Declasifying; 9 | 10 | export type SwapTokenLogic = Logic; 11 | 12 | export async function getSwapTokenTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.syncswap.SwapTokenLogic.rid); 14 | } 15 | 16 | export async function getSwapTokenQuotation( 17 | chainId: number, 18 | params: SwapTokenParams 19 | ): Promise { 20 | return quote(chainId, logics.syncswap.SwapTokenLogic.rid, params); 21 | } 22 | 23 | export function newSwapTokenLogic(fields: SwapTokenFields): SwapTokenLogic { 24 | return { rid: logics.syncswap.SwapTokenLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/uniswap-v3/index.ts: -------------------------------------------------------------------------------- 1 | export * from './swap-token'; 2 | -------------------------------------------------------------------------------- /packages/api/src/protocols/uniswap-v3/swap-token.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type SwapTokenParams = common.Declasifying; 7 | 8 | export type SwapTokenFields = common.Declasifying; 9 | 10 | export type SwapTokenLogic = Logic; 11 | 12 | export async function getSwapTokenTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.uniswapv3.SwapTokenLogic.rid); 14 | } 15 | 16 | export async function getSwapTokenQuotation( 17 | chainId: number, 18 | params: SwapTokenParams 19 | ): Promise { 20 | return quote(chainId, logics.uniswapv3.SwapTokenLogic.rid, params); 21 | } 22 | 23 | export function newSwapTokenLogic(fields: SwapTokenFields): SwapTokenLogic { 24 | return { rid: logics.uniswapv3.SwapTokenLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/utility/custom-data.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import * as logics from '@protocolink/logics'; 4 | 5 | export type CustomDataFields = common.Declasifying; 6 | 7 | export type CustomDataLogic = Logic; 8 | 9 | export function newCustomDataLogic(fields: CustomDataFields): CustomDataLogic { 10 | return { rid: logics.utility.CustomDataLogic.rid, fields }; 11 | } 12 | -------------------------------------------------------------------------------- /packages/api/src/protocols/utility/index.ts: -------------------------------------------------------------------------------- 1 | export * from './custom-data'; 2 | export * from './flash-loan-aggregator'; 3 | export * from './multi-send'; 4 | export * from './send-token'; 5 | export * from './wrapped-native-token'; 6 | -------------------------------------------------------------------------------- /packages/api/src/protocols/utility/multi-send.test.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | import { expect } from 'chai'; 3 | import { getMultiSendTokenList } from './multi-send'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('Utility MultiSendLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.utility.MultiSendLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getMultiSendTokenList(chainId); 11 | expect(tokenList).to.have.lengthOf.above(0); 12 | }); 13 | }); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /packages/api/src/protocols/utility/multi-send.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type MultiSendFields = common.Declasifying; 7 | 8 | export type MultiSendLogic = Logic; 9 | 10 | export async function getMultiSendTokenList(chainId: number): Promise { 11 | return getProtocolTokenList(chainId, logics.utility.MultiSendLogic.rid); 12 | } 13 | 14 | export function newMultiSendLogic(fields: MultiSendFields): MultiSendLogic { 15 | return { rid: logics.utility.MultiSendLogic.rid, fields }; 16 | } 17 | -------------------------------------------------------------------------------- /packages/api/src/protocols/utility/send-token.test.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | import { expect } from 'chai'; 3 | import { getSendTokenTokenList } from './send-token'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | describe('Utility SendTokenLogic', function () { 7 | context('Test getTokenList', async function () { 8 | logics.utility.SendTokenLogic.supportedChainIds.forEach((chainId) => { 9 | it(`network: ${common.toNetworkId(chainId)}`, async function () { 10 | const tokenList = await getSendTokenTokenList(chainId); 11 | expect(tokenList).to.have.lengthOf.above(0); 12 | }); 13 | }); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /packages/api/src/protocols/utility/send-token.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type SendTokenFields = common.Declasifying; 7 | 8 | export type SendTokenLogic = Logic; 9 | 10 | export async function getSendTokenTokenList(chainId: number): Promise { 11 | return getProtocolTokenList(chainId, logics.utility.SendTokenLogic.rid); 12 | } 13 | 14 | export function newSendTokenLogic(fields: SendTokenFields): SendTokenLogic { 15 | return { rid: logics.utility.SendTokenLogic.rid, fields }; 16 | } 17 | -------------------------------------------------------------------------------- /packages/api/src/protocols/utility/wrapped-native-token.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type WrappedNativeTokenParams = common.Declasifying; 7 | 8 | export type WrappedNativeTokenFields = common.Declasifying; 9 | 10 | export type WrappedNativeTokenLogic = Logic; 11 | 12 | export async function getWrappedNativeTokenTokenList( 13 | chainId: number 14 | ): Promise { 15 | return getProtocolTokenList(chainId, logics.utility.WrappedNativeTokenLogic.rid); 16 | } 17 | 18 | export async function getWrappedNativeTokenQuotation( 19 | chainId: number, 20 | params: WrappedNativeTokenParams 21 | ): Promise { 22 | return quote(chainId, logics.utility.WrappedNativeTokenLogic.rid, params); 23 | } 24 | 25 | export function newWrappedNativeTokenLogic(fields: WrappedNativeTokenFields): WrappedNativeTokenLogic { 26 | return { rid: logics.utility.WrappedNativeTokenLogic.rid, fields }; 27 | } 28 | -------------------------------------------------------------------------------- /packages/api/src/protocols/wagmi/index.ts: -------------------------------------------------------------------------------- 1 | export * from './swap-token'; 2 | -------------------------------------------------------------------------------- /packages/api/src/protocols/wagmi/swap-token.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type SwapTokenParams = common.Declasifying; 7 | 8 | export type SwapTokenFields = common.Declasifying; 9 | 10 | export type SwapTokenLogic = Logic; 11 | 12 | export async function getSwapTokenTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.wagmi.SwapTokenLogic.rid); 14 | } 15 | 16 | export async function getSwapTokenQuotation( 17 | chainId: number, 18 | params: SwapTokenParams 19 | ): Promise { 20 | return quote(chainId, logics.wagmi.SwapTokenLogic.rid, params); 21 | } 22 | 23 | export function newSwapTokenLogic(fields: SwapTokenFields): SwapTokenLogic { 24 | return { rid: logics.wagmi.SwapTokenLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/protocols/zeroex-v4/index.ts: -------------------------------------------------------------------------------- 1 | export * from './swap-token'; 2 | -------------------------------------------------------------------------------- /packages/api/src/protocols/zeroex-v4/swap-token.ts: -------------------------------------------------------------------------------- 1 | import { Logic } from 'src/types'; 2 | import * as common from '@protocolink/common'; 3 | import { getProtocolTokenList, quote } from 'src/api'; 4 | import * as logics from '@protocolink/logics'; 5 | 6 | export type SwapTokenParams = common.Declasifying; 7 | 8 | export type SwapTokenFields = common.Declasifying; 9 | 10 | export type SwapTokenLogic = Logic; 11 | 12 | export async function getSwapTokenTokenList(chainId: number): Promise { 13 | return getProtocolTokenList(chainId, logics.zeroexv4.SwapTokenLogic.rid); 14 | } 15 | 16 | export async function getSwapTokenQuotation( 17 | chainId: number, 18 | params: SwapTokenParams 19 | ): Promise { 20 | return quote(chainId, logics.zeroexv4.SwapTokenLogic.rid, params); 21 | } 22 | 23 | export function newSwapTokenLogic(fields: SwapTokenFields): SwapTokenLogic { 24 | return { rid: logics.zeroexv4.SwapTokenLogic.rid, fields }; 25 | } 26 | -------------------------------------------------------------------------------- /packages/api/src/types.ts: -------------------------------------------------------------------------------- 1 | import { PermitBatchData, PermitSingleData } from '@uniswap/permit2-sdk'; 2 | import * as common from '@protocolink/common'; 3 | import * as core from '@protocolink/core'; 4 | 5 | export interface Logic { 6 | rid: string; 7 | fields: TFields; 8 | } 9 | 10 | export type Permit2Type = 'permit' | 'approve'; 11 | 12 | export interface Referral { 13 | collector: string; 14 | rate: number; 15 | } 16 | 17 | export interface RouterData { 18 | chainId: number; 19 | account: string; 20 | logics: Logic[]; 21 | permitData?: PermitSingleData | PermitBatchData; 22 | permitSig?: string; 23 | referral?: string; 24 | referrals?: Referral[]; 25 | customFees?: Fee[]; 26 | } 27 | 28 | export interface Fee { 29 | rid: string; 30 | feeAmount: common.TokenAmount; 31 | } 32 | 33 | export interface RouterDataEstimateResult { 34 | funds: common.TokenAmounts; 35 | balances: common.TokenAmounts; 36 | fees: Fee[]; 37 | approvals: common.TransactionRequest[]; 38 | permitData?: PermitSingleData | PermitBatchData; 39 | } 40 | 41 | export type FlashLoanLogicFields = Pick & { id: string; isLoan: boolean }; 42 | 43 | export type FlashLoanFields = common.Declasifying; 44 | 45 | export type FlashLoanLogic = Logic; 46 | -------------------------------------------------------------------------------- /packages/api/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "dist", 5 | "declarationDir": "dist", 6 | "rootDir": "src" 7 | }, 8 | "exclude": ["**/*.test.ts", "examples/**/*"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/api/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "paths": { 6 | "src/*": ["src/*"], 7 | "test/*": ["test/*"], 8 | "@protocolink/api": ["src"] 9 | } 10 | }, 11 | "include": ["src/**/*", "examples/**/*"] 12 | } 13 | -------------------------------------------------------------------------------- /packages/common/README.md: -------------------------------------------------------------------------------- 1 | # @protocolink/common 2 | 3 | The common sdk for Protocolink. 4 | 5 | ## Install 6 | 7 | Install the package via `npm`: 8 | 9 | ```sh 10 | npm install @protocolink/common 11 | ``` 12 | 13 | or `yarn`: 14 | 15 | ```sh 16 | yarn add @protocolink/common 17 | ``` 18 | -------------------------------------------------------------------------------- /packages/common/hardhat.config.ts: -------------------------------------------------------------------------------- 1 | import config from '../../hardhat.config'; 2 | 3 | export default config; 4 | -------------------------------------------------------------------------------- /packages/common/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@protocolink/common", 3 | "version": "0.5.5", 4 | "description": "Protocolink Common SDK", 5 | "keywords": [ 6 | "furucombo", 7 | "protocolink" 8 | ], 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/dinngo/protocolink-js-sdk.git", 12 | "directory": "packages/common" 13 | }, 14 | "license": "MIT", 15 | "main": "dist/index.js", 16 | "types": "dist/index.d.ts", 17 | "files": [ 18 | "dist/**/*" 19 | ], 20 | "scripts": { 21 | "build": "rm -rf dist && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json", 22 | "format": "yarn sort-package-json", 23 | "lint": "eslint --fix src", 24 | "prepublishOnly": "yarn build", 25 | "test": "mocha", 26 | "test:e2e": "hardhat test", 27 | "test:unit": "mocha --recursive src", 28 | "typechain": "typechain --target ethers-v5 --out-dir src/contracts src/abis/*.json" 29 | }, 30 | "dependencies": { 31 | "@types/lodash": "^4.14.195", 32 | "axios": "^1.3.6", 33 | "axios-retry": "^3.5.1", 34 | "bignumber.js": "^9.1.1", 35 | "ethers": "^5.7.2", 36 | "lodash": "^4.17.21", 37 | "tiny-invariant": "^1.3.1", 38 | "type-fest": "^3.12.0", 39 | "zksync-web3": "^0.14.3" 40 | }, 41 | "devDependencies": { 42 | "@protocolink/test-helpers": "*" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /packages/common/src/abis/WETH.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "constant": false, 4 | "inputs": [], 5 | "name": "deposit", 6 | "outputs": [], 7 | "payable": true, 8 | "stateMutability": "payable", 9 | "type": "function" 10 | }, 11 | { 12 | "constant": false, 13 | "inputs": [ 14 | { 15 | "name": "wad", 16 | "type": "uint256" 17 | } 18 | ], 19 | "name": "withdraw", 20 | "outputs": [], 21 | "payable": false, 22 | "stateMutability": "nonpayable", 23 | "type": "function" 24 | } 25 | ] 26 | -------------------------------------------------------------------------------- /packages/common/src/constants.ts: -------------------------------------------------------------------------------- 1 | export const BPS_BASE = 10_000; 2 | -------------------------------------------------------------------------------- /packages/common/src/contracts/common.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | import type { Listener } from '@ethersproject/providers'; 5 | import type { Event, EventFilter } from 'ethers'; 6 | 7 | export interface TypedEvent = any, TArgsObject = any> extends Event { 8 | args: TArgsArray & TArgsObject; 9 | } 10 | 11 | export interface TypedEventFilter<_TEvent extends TypedEvent> extends EventFilter {} 12 | 13 | export interface TypedListener { 14 | (...listenerArg: [...__TypechainArgsArray, TEvent]): void; 15 | } 16 | 17 | type __TypechainArgsArray = T extends TypedEvent ? U : never; 18 | 19 | export interface OnEvent { 20 | (eventFilter: TypedEventFilter, listener: TypedListener): TRes; 21 | (eventName: string, listener: Listener): TRes; 22 | } 23 | 24 | export type MinEthersFactory = { 25 | deploy(...a: ARGS[]): Promise; 26 | }; 27 | 28 | export type GetContractTypeFromFactory = F extends MinEthersFactory ? C : never; 29 | 30 | export type GetARGsTypeFromFactory = F extends MinEthersFactory ? Parameters : never; 31 | -------------------------------------------------------------------------------- /packages/common/src/contracts/factories/WETH__factory.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | 5 | import { Contract, Signer, utils } from 'ethers'; 6 | import type { Provider } from '@ethersproject/providers'; 7 | import type { WETH, WETHInterface } from '../WETH'; 8 | 9 | const _abi = [ 10 | { 11 | constant: false, 12 | inputs: [], 13 | name: 'deposit', 14 | outputs: [], 15 | payable: true, 16 | stateMutability: 'payable', 17 | type: 'function', 18 | }, 19 | { 20 | constant: false, 21 | inputs: [ 22 | { 23 | name: 'wad', 24 | type: 'uint256', 25 | }, 26 | ], 27 | name: 'withdraw', 28 | outputs: [], 29 | payable: false, 30 | stateMutability: 'nonpayable', 31 | type: 'function', 32 | }, 33 | ] as const; 34 | 35 | export class WETH__factory { 36 | static readonly abi = _abi; 37 | static createInterface(): WETHInterface { 38 | return new utils.Interface(_abi) as WETHInterface; 39 | } 40 | static connect(address: string, signerOrProvider: Signer | Provider): WETH { 41 | return new Contract(address, _abi, signerOrProvider) as WETH; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /packages/common/src/contracts/factories/index.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | export { ERC20__factory } from './ERC20__factory'; 5 | export { Multicall3__factory } from './Multicall3__factory'; 6 | export { WETH__factory } from './WETH__factory'; 7 | -------------------------------------------------------------------------------- /packages/common/src/contracts/index.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | export type { ERC20 } from './ERC20'; 5 | export type { Multicall3 } from './Multicall3'; 6 | export type { WETH } from './WETH'; 7 | export * as factories from './factories'; 8 | export { ERC20__factory } from './factories/ERC20__factory'; 9 | export { Multicall3__factory } from './factories/Multicall3__factory'; 10 | export { WETH__factory } from './factories/WETH__factory'; 11 | -------------------------------------------------------------------------------- /packages/common/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './constants'; 2 | export * from './contracts'; 3 | export * from './networks'; 4 | export * from './tokens'; 5 | export * from './transaction'; 6 | export * from './utils'; 7 | export * from './web3-toolkit'; 8 | -------------------------------------------------------------------------------- /packages/common/src/tokens/constants.ts: -------------------------------------------------------------------------------- 1 | export const ELASTIC_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'; 2 | -------------------------------------------------------------------------------- /packages/common/src/tokens/data/iota.json: -------------------------------------------------------------------------------- 1 | { 2 | "IOTA": { 3 | "chainId": 8822, 4 | "address": "0x0000000000000000000000000000000000000000", 5 | "decimals": 18, 6 | "symbol": "IOTA", 7 | "name": "IOTA", 8 | "logoUri": "https://cdn.furucombo.app/assets/img/token/IOTA.svg" 9 | }, 10 | "wIOTA": { 11 | "chainId": 8822, 12 | "address": "0x6e47f8d48a01b44DF3fFF35d258A10A3AEdC114c", 13 | "decimals": 18, 14 | "symbol": "wIOTA", 15 | "name": "wIOTA", 16 | "logoUri": "https://cdn.furucombo.app/assets/img/token/wIOTA.svg" 17 | }, 18 | "WETH": { 19 | "chainId": 8822, 20 | "address": "0x160345fC359604fC6e70E3c5fAcbdE5F7A9342d8", 21 | "decimals": 18, 22 | "symbol": "WETH", 23 | "name": "WETH", 24 | "logoUri": "https://cdn.furucombo.app/assets/img/token/WETH.svg" 25 | }, 26 | "USDT": { 27 | "chainId": 8822, 28 | "address": "0xC1B8045A6ef2934Cf0f78B0dbD489969Fa9Be7E4", 29 | "decimals": 6, 30 | "symbol": "USDT", 31 | "name": "Tether USD", 32 | "logoUri": "https://cdn.furucombo.app/assets/img/token/USDT.svg" 33 | }, 34 | "USDC.e": { 35 | "chainId": 8822, 36 | "address": "0xFbDa5F676cB37624f28265A144A48B0d6e87d3b6", 37 | "decimals": 6, 38 | "symbol": "USDC.e", 39 | "name": "Bridged USDC (Stargate) (USDC.e)", 40 | "logoUri": "https://cdn.furucombo.app/assets/img/token/USDC.svg" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /packages/common/src/tokens/index.ts: -------------------------------------------------------------------------------- 1 | export * from './constants'; 2 | export * from './token'; 3 | export * from './token-amount'; 4 | export * from './transform'; 5 | export * from './utils'; 6 | -------------------------------------------------------------------------------- /packages/common/src/transaction.ts: -------------------------------------------------------------------------------- 1 | import { BigNumberish, constants, providers } from 'ethers'; 2 | import { ERC20__factory } from './contracts'; 3 | import { SetRequired } from 'type-fest'; 4 | import { Token } from './tokens'; 5 | 6 | export type TransactionRequest = SetRequired< 7 | Pick, 8 | 'to' | 'data' 9 | >; 10 | 11 | export function newErc20ApproveTransactionRequest( 12 | token: Token, 13 | spender: string, 14 | amountWei?: BigNumberish 15 | ): TransactionRequest { 16 | const iface = ERC20__factory.createInterface(); 17 | const data = iface.encodeFunctionData('approve', [ 18 | spender, 19 | amountWei !== undefined ? amountWei : constants.MaxUint256, 20 | ]); 21 | 22 | return { to: token.address, data }; 23 | } 24 | -------------------------------------------------------------------------------- /packages/common/src/utils/abi.ts: -------------------------------------------------------------------------------- 1 | export function getParamOffset(paramIndex: number) { 2 | return paramIndex * 32; 3 | } 4 | -------------------------------------------------------------------------------- /packages/common/src/utils/error.test.ts: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import { getErrorStackCallerPaths } from './error'; 3 | import path from 'path'; 4 | 5 | it('Test getErrorStackCallerPaths', function () { 6 | const callerPaths = getErrorStackCallerPaths(); 7 | expect(path.basename(callerPaths[0])).to.eq('error.ts'); 8 | expect(path.basename(callerPaths[1])).to.eq('error.test.ts'); 9 | expect(path.basename(path.resolve(callerPaths[0], '..'))).to.eq('utils'); 10 | expect(path.basename(path.resolve(callerPaths[0], '..', '..'))).to.eq('src'); 11 | }); 12 | -------------------------------------------------------------------------------- /packages/common/src/utils/error.ts: -------------------------------------------------------------------------------- 1 | export function getErrorStackCallerPaths() { 2 | const filePaths: string[] = []; 3 | const stack = new Error().stack; 4 | if (stack) { 5 | const stackLines = stack.split('\n'); 6 | for (const stackLine of stackLines) { 7 | const matches = stackLine.match(/^[^\/]+([^\:]+)\:/); 8 | if (matches) { 9 | filePaths.push(matches[1]); 10 | } 11 | } 12 | } 13 | 14 | return filePaths; 15 | } 16 | -------------------------------------------------------------------------------- /packages/common/src/utils/http.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | import axiosRetry from 'axios-retry'; 3 | 4 | axiosRetry(axios, { retries: 3, retryDelay: axiosRetry.exponentialDelay }); 5 | 6 | export { axios }; 7 | -------------------------------------------------------------------------------- /packages/common/src/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from './abi'; 2 | export * from './bignumber'; 3 | export * from './bps'; 4 | export * from './error'; 5 | export * from './web3'; 6 | -------------------------------------------------------------------------------- /packages/common/src/utils/web3.test.ts: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import { shortenAddress } from './web3'; 3 | 4 | describe('Test shortenAddress', function () { 5 | const testCases = [ 6 | { address: '0xDAFEA492D9c6733ae3d56b7Ed1ADB60692c98Bc5', expected: '0xDAFE...8Bc5' }, 7 | { address: '0xd8C1CECCa51d5d97a70a35E194bb6670B85d8576', expected: '0xd8C1...8576' }, 8 | { address: '0x6887246668a3b87F54DeB3b94Ba47a6f63F32985', digits: 6, expected: '0x688724...F32985' }, 9 | ]; 10 | 11 | testCases.forEach(({ address, digits, expected }, i) => { 12 | it(`case ${i + 1}`, function () { 13 | expect(shortenAddress(address, digits)).to.eq(expected); 14 | }); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /packages/common/src/utils/web3.ts: -------------------------------------------------------------------------------- 1 | import invariant from 'tiny-invariant'; 2 | import { utils } from 'ethers'; 3 | 4 | export function shortenAddress(address: string, digits = 4): string { 5 | invariant(utils.isAddress(address), 'invalid address'); 6 | return `${address.substring(0, digits + 2)}...${address.substring(42 - digits)}`; 7 | } 8 | 9 | export function shortenTransactionHash(hash: string, digits = 4): string { 10 | return `${hash.substring(0, digits + 2)}...${hash.substring(66 - digits)}`; 11 | } 12 | -------------------------------------------------------------------------------- /packages/common/test/init.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | 3 | if (process.env.MAINNET_RPC_URL) { 4 | common.setNetwork(common.ChainId.mainnet, { rpcUrl: process.env.MAINNET_RPC_URL }); 5 | } 6 | -------------------------------------------------------------------------------- /packages/common/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "dist", 5 | "declarationDir": "dist", 6 | "rootDir": "src" 7 | }, 8 | "exclude": ["test/**/*", "**/*.test.ts", "hardhat.config.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/common/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "paths": { 6 | "src/*": ["src/*"], 7 | "test/*": ["test/*"] 8 | } 9 | }, 10 | "include": ["src/**/*", "test/**/*", "hardhat.config.ts"] 11 | } 12 | -------------------------------------------------------------------------------- /packages/core/README.md: -------------------------------------------------------------------------------- 1 | # @protocolink/core 2 | 3 | The core sdk for Protocolink. 4 | 5 | ## Install 6 | 7 | Install the package via `npm`: 8 | 9 | ```sh 10 | npm install @protocolink/core 11 | ``` 12 | 13 | or `yarn`: 14 | 15 | ```sh 16 | yarn add @protocolink/core 17 | ``` 18 | -------------------------------------------------------------------------------- /packages/core/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@protocolink/core", 3 | "version": "0.6.4", 4 | "description": "Protocolink Core SDK", 5 | "keywords": [ 6 | "furucombo", 7 | "protocolink" 8 | ], 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/dinngo/protocolink-js-sdk.git", 12 | "directory": "packages/dev" 13 | }, 14 | "license": "MIT", 15 | "main": "dist/index.js", 16 | "types": "dist/index.d.ts", 17 | "files": [ 18 | "dist/**/*" 19 | ], 20 | "scripts": { 21 | "build": "rm -rf dist && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json", 22 | "format": "yarn sort-package-json", 23 | "lint": "eslint --fix src", 24 | "prepublishOnly": "yarn build", 25 | "test": "mocha", 26 | "test:unit": "mocha --recursive src", 27 | "typechain": "rm -rf src/contracts && typechain --target ethers-v5 --out-dir src/contracts src/abis/*.json && pretty-quick" 28 | }, 29 | "dependencies": { 30 | "@protocolink/common": "^0.5.5", 31 | "@uniswap/permit2-sdk": "^1.2.0", 32 | "ethers": "^5.7.2", 33 | "tiny-invariant": "^1.3.1" 34 | }, 35 | "devDependencies": { 36 | "@protocolink/test-helpers": "*" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /packages/core/src/constants.ts: -------------------------------------------------------------------------------- 1 | export const BPS_NOT_USED = 0; 2 | 3 | export const OFFSET_NOT_USED = '0x8000000000000000000000000000000000000000000000000000000000000000'; // 2^255 4 | 5 | export const PERMIT_EXPIRATION = 2592000; // 30d 6 | 7 | export const PERMIT_SIG_DEADLINE = 86400; // 1d 8 | 9 | export const LOGIC_BATCH_TYPED_DATA_TYPES = { 10 | LogicBatch: [ 11 | { name: 'logics', type: 'Logic[]' }, 12 | { name: 'fees', type: 'Fee[]' }, 13 | { name: 'referrals', type: 'bytes32[]' }, 14 | { name: 'deadline', type: 'uint256' }, 15 | ], 16 | Logic: [ 17 | { name: 'to', type: 'address' }, 18 | { name: 'data', type: 'bytes' }, 19 | { name: 'inputs', type: 'Input[]' }, 20 | { name: 'wrapMode', type: 'uint8' }, 21 | { name: 'approveTo', type: 'address' }, 22 | { name: 'callback', type: 'address' }, 23 | ], 24 | Fee: [ 25 | { name: 'token', type: 'address' }, 26 | { name: 'amount', type: 'uint256' }, 27 | { name: 'metadata', type: 'bytes32' }, 28 | ], 29 | Input: [ 30 | { name: 'token', type: 'address' }, 31 | { name: 'balanceBps', type: 'uint256' }, 32 | { name: 'amountOrOffset', type: 'uint256' }, 33 | ], 34 | }; 35 | -------------------------------------------------------------------------------- /packages/core/src/contracts/common.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | import type { Listener } from '@ethersproject/providers'; 5 | import type { Event, EventFilter } from 'ethers'; 6 | 7 | export interface TypedEvent = any, TArgsObject = any> extends Event { 8 | args: TArgsArray & TArgsObject; 9 | } 10 | 11 | export interface TypedEventFilter<_TEvent extends TypedEvent> extends EventFilter {} 12 | 13 | export interface TypedListener { 14 | (...listenerArg: [...__TypechainArgsArray, TEvent]): void; 15 | } 16 | 17 | type __TypechainArgsArray = T extends TypedEvent ? U : never; 18 | 19 | export interface OnEvent { 20 | (eventFilter: TypedEventFilter, listener: TypedListener): TRes; 21 | (eventName: string, listener: Listener): TRes; 22 | } 23 | 24 | export type MinEthersFactory = { 25 | deploy(...a: ARGS[]): Promise; 26 | }; 27 | 28 | export type GetContractTypeFromFactory = F extends MinEthersFactory ? C : never; 29 | 30 | export type GetARGsTypeFromFactory = F extends MinEthersFactory ? Parameters : never; 31 | -------------------------------------------------------------------------------- /packages/core/src/contracts/factories/index.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | export { Agent__factory } from './Agent__factory'; 5 | export { Permit2__factory } from './Permit2__factory'; 6 | export { Router__factory } from './Router__factory'; 7 | -------------------------------------------------------------------------------- /packages/core/src/contracts/index.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | export type { Agent } from './Agent'; 5 | export type { Permit2 } from './Permit2'; 6 | export type { Router } from './Router'; 7 | export * as factories from './factories'; 8 | export { Agent__factory } from './factories/Agent__factory'; 9 | export { Permit2__factory } from './factories/Permit2__factory'; 10 | export { Router__factory } from './factories/Router__factory'; 11 | -------------------------------------------------------------------------------- /packages/core/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './configs'; 2 | export * from './constants'; 3 | export * from './contracts'; 4 | export * from './contracts/Router'; 5 | export * from './logic'; 6 | export * from './logic-types'; 7 | export * from './logic-utils'; 8 | export * from './router-kit'; 9 | export * from './router-utils'; 10 | -------------------------------------------------------------------------------- /packages/core/src/logic.ts: -------------------------------------------------------------------------------- 1 | import { DataType } from './contracts/Router'; 2 | import { RouterKit } from './router-kit'; 3 | 4 | export abstract class Logic extends RouterKit { 5 | static id: string; 6 | static protocolId: string; 7 | static get rid() { 8 | return `${this.protocolId}:${this.id}`; 9 | } 10 | static supportedChainIds: number[] = []; 11 | } 12 | 13 | export interface LogicTokenListInterface { 14 | getTokenList(): any; 15 | } 16 | 17 | export interface LogicOracleInterface { 18 | quote(params: any): any; 19 | } 20 | 21 | export interface LogicBuilderInterface { 22 | build(fields: any, options?: any): Promise; 23 | } 24 | 25 | export interface LogicMultiBuilderInterface { 26 | build(fields: any, options?: any): Promise; 27 | } 28 | 29 | export interface LogicClassInterface { 30 | new (...args: any[]): Logic; 31 | id: string; 32 | protocolId: string; 33 | rid: string; 34 | supportedChainIds: number[]; 35 | } 36 | -------------------------------------------------------------------------------- /packages/core/src/router-utils.ts: -------------------------------------------------------------------------------- 1 | import { BigNumber, utils } from 'ethers'; 2 | import { PermitBatch, PermitSingle } from '@uniswap/permit2-sdk'; 3 | 4 | export function getDeadline(expiration: number) { 5 | return Math.floor(Date.now() / 1000) + expiration; 6 | } 7 | 8 | export function isPermitSingle(permit: PermitSingle | PermitBatch): permit is PermitSingle { 9 | return !Array.isArray(permit.details); 10 | } 11 | 12 | export function encodeReferral(collector: string, rate: number) { 13 | return BigNumber.from(collector.padEnd(66, '0')).or(BigNumber.from(rate)).toHexString(); 14 | } 15 | 16 | export function decodeReferral(referral: string) { 17 | return { 18 | collector: utils.getAddress(referral.substring(0, 42)), 19 | rate: BigNumber.from(`0x${referral.slice(42)}`).toNumber(), 20 | }; 21 | } 22 | -------------------------------------------------------------------------------- /packages/core/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "dist", 5 | "declarationDir": "dist", 6 | "rootDir": "src" 7 | }, 8 | "exclude": ["test/**/*", "**/*.test.ts", "hardhat.config.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/core/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "paths": { 6 | "src/*": ["src/*"] 7 | } 8 | }, 9 | "include": ["src/**/*", "test/**/*", "hardhat.config.ts"] 10 | } 11 | -------------------------------------------------------------------------------- /packages/lending/.mocharc.js: -------------------------------------------------------------------------------- 1 | // https://github.com/mochajs/mocha/blob/master/example/config/.mocharc.js 2 | 3 | module.exports = { 4 | extension: 'ts', 5 | require: [ 6 | 'ts-node/register', 7 | '@nomicfoundation/hardhat-chai-matchers/internal/add-chai-matchers', 8 | 'test/unit-test-init.ts', 9 | ], 10 | timeout: 30000, 11 | }; 12 | -------------------------------------------------------------------------------- /packages/lending/README.md: -------------------------------------------------------------------------------- 1 | # @protocolink/lending 2 | 3 | The lending sdk for Protocolink. 4 | 5 | ## Install 6 | 7 | Install the package via `npm`: 8 | 9 | ```sh 10 | npm install @protocolink/lending 11 | ``` 12 | 13 | or `yarn`: 14 | 15 | ```sh 16 | yarn add @protocolink/lending 17 | ``` 18 | -------------------------------------------------------------------------------- /packages/lending/hardhat.config.ts: -------------------------------------------------------------------------------- 1 | import { HardhatUserConfig } from 'hardhat/config'; 2 | import rootConfig from '../../hardhat.config'; 3 | import { setup } from 'test/hooks'; 4 | 5 | const config: HardhatUserConfig = { 6 | ...rootConfig, 7 | mocha: { 8 | ...rootConfig.mocha, 9 | rootHooks: { beforeAll: [setup] }, 10 | }, 11 | }; 12 | 13 | export default config; 14 | -------------------------------------------------------------------------------- /packages/lending/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@protocolink/lending", 3 | "version": "2.1.9", 4 | "description": "Protocolink Lending SDK", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/dinngo/protocolink-js-sdk.git", 8 | "directory": "packages/lending" 9 | }, 10 | "license": "MIT", 11 | "main": "dist/index.js", 12 | "types": "dist/index.d.ts", 13 | "files": [ 14 | "dist/**/*" 15 | ], 16 | "scripts": { 17 | "build": "rm -rf dist && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json", 18 | "format": "yarn sort-package-json", 19 | "lint": "eslint --fix src", 20 | "prepublishOnly": "yarn build", 21 | "test": "mocha", 22 | "test:e2e": "hardhat test", 23 | "test:unit": "mocha --recursive src" 24 | }, 25 | "dependencies": { 26 | "@aave/math-utils": "^1.21.0", 27 | "@protocolink/api": "^1.4.8", 28 | "@protocolink/common": "^0.5.5", 29 | "@protocolink/core": "^0.6.4", 30 | "@protocolink/logics": "^1.8.9", 31 | "bignumber.js": "^9.1.1", 32 | "decimal.js-light": "^2.5.1" 33 | }, 34 | "devDependencies": { 35 | "@protocolink/test-helpers": "*" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /packages/lending/src/adapter.type.ts: -------------------------------------------------------------------------------- 1 | import { Portfolio } from './protocol.portfolio'; 2 | import * as apisdk from '@protocolink/api'; 3 | import * as common from '@protocolink/common'; 4 | 5 | export interface OpenOperationInput { 6 | account: string; 7 | portfolio: Portfolio; 8 | zapToken: common.Token; 9 | zapAmount: string; 10 | collateralToken: common.Token; 11 | collateralAmount?: string; 12 | debtToken: common.Token; 13 | debtAmount?: string; 14 | slippage?: number; 15 | } 16 | 17 | export interface CloseOperationInput { 18 | account: string; 19 | portfolio: Portfolio; 20 | withdrawalToken: common.Token; 21 | slippage?: number; 22 | } 23 | 24 | export interface OperationInput { 25 | account: string; 26 | portfolio: Portfolio; 27 | srcToken: common.Token; 28 | srcAmount: string; 29 | destToken: common.Token; 30 | slippage?: number; 31 | isRepayAll?: boolean; 32 | } 33 | 34 | export class OperationError extends Error { 35 | name: string; 36 | code: string; 37 | 38 | constructor(name: string, code: string) { 39 | super(`${name}: ${code}`); 40 | this.name = name; 41 | this.code = code; 42 | } 43 | } 44 | 45 | export type OperationOutput = { 46 | destAmount: string; 47 | afterPortfolio: Portfolio; 48 | error?: OperationError; 49 | logics: apisdk.Logic[]; 50 | }; 51 | -------------------------------------------------------------------------------- /packages/lending/src/adapter.utils.test.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | import { expect } from 'chai'; 3 | import { scaleRepayAmount } from './adapter.utils'; 4 | 5 | describe('Test scaleRepayAmount', function () { 6 | const testCases = [ 7 | { token: common.mainnetTokens.WETH, amount: '1', scale: 100, expected: '1.01' }, 8 | { token: common.mainnetTokens.WETH, amount: '0.00001', scale: 100, expected: '0.0000101' }, 9 | { token: common.mainnetTokens.USDC, amount: '1', scale: 100, expected: '1.01' }, 10 | { token: common.mainnetTokens.USDC, amount: '0.00001', scale: 100, expected: '0.00001' }, 11 | ]; 12 | 13 | testCases.forEach(({ token, amount, scale, expected }, i) => { 14 | it(`case ${i + 1}`, async function () { 15 | expect(scaleRepayAmount(token, amount, scale)).to.eq(expected); 16 | }); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /packages/lending/src/adapter.utils.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | 3 | /** 4 | * Scales the repayment amount based on a specified scale factor. 5 | * @param token The token involved in the scaling. 6 | * @param amount The initial amount to be scaled. 7 | * @param scale The scaling factor in basis points (bps). 8 | * @returns The scaled repayment amount. 9 | */ 10 | export function scaleRepayAmount(token: common.Token, amount: string, scale: number) { 11 | return common.toBigUnit(common.calcSlippage(common.toSmallUnit(amount, token.decimals), -scale), token.decimals); 12 | } 13 | -------------------------------------------------------------------------------- /packages/lending/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './adapter'; 2 | export * from './adapter.type'; 3 | export * from './protocol'; 4 | export * from './protocol.portfolio'; 5 | export * from './protocol.type'; 6 | export * as protocols from './protocols'; 7 | export * as swappers from './swappers'; 8 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/aave-v2/abis/AToken.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [ 4 | { 5 | "internalType": "address", 6 | "name": "user", 7 | "type": "address" 8 | } 9 | ], 10 | "name": "scaledBalanceOf", 11 | "outputs": [ 12 | { 13 | "internalType": "uint256", 14 | "name": "", 15 | "type": "uint256" 16 | } 17 | ], 18 | "stateMutability": "view", 19 | "type": "function" 20 | }, 21 | { 22 | "constant": true, 23 | "inputs": [], 24 | "name": "totalSupply", 25 | "outputs": [ 26 | { 27 | "name": "", 28 | "type": "uint256" 29 | } 30 | ], 31 | "payable": false, 32 | "stateMutability": "view", 33 | "type": "function" 34 | } 35 | ] 36 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/aave-v2/abis/ETHPriceFeed.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [], 4 | "name": "latestAnswer", 5 | "outputs": [ 6 | { 7 | "internalType": "int256", 8 | "name": "", 9 | "type": "int256" 10 | } 11 | ], 12 | "stateMutability": "view", 13 | "type": "function" 14 | } 15 | ] 16 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/aave-v2/abis/PriceOracle.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [ 4 | { 5 | "internalType": "address", 6 | "name": "asset", 7 | "type": "address" 8 | } 9 | ], 10 | "name": "getAssetPrice", 11 | "outputs": [ 12 | { 13 | "internalType": "uint256", 14 | "name": "", 15 | "type": "uint256" 16 | } 17 | ], 18 | "stateMutability": "view", 19 | "type": "function" 20 | }, 21 | { 22 | "inputs": [ 23 | { 24 | "internalType": "address[]", 25 | "name": "assets", 26 | "type": "address[]" 27 | } 28 | ], 29 | "name": "getAssetsPrices", 30 | "outputs": [ 31 | { 32 | "internalType": "uint256[]", 33 | "name": "", 34 | "type": "uint256[]" 35 | } 36 | ], 37 | "stateMutability": "view", 38 | "type": "function" 39 | } 40 | ] 41 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/aave-v2/contracts/common.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | import type { Listener } from '@ethersproject/providers'; 5 | import type { Event, EventFilter } from 'ethers'; 6 | 7 | export interface TypedEvent = any, TArgsObject = any> extends Event { 8 | args: TArgsArray & TArgsObject; 9 | } 10 | 11 | export interface TypedEventFilter<_TEvent extends TypedEvent> extends EventFilter {} 12 | 13 | export interface TypedListener { 14 | (...listenerArg: [...__TypechainArgsArray, TEvent]): void; 15 | } 16 | 17 | type __TypechainArgsArray = T extends TypedEvent ? U : never; 18 | 19 | export interface OnEvent { 20 | (eventFilter: TypedEventFilter, listener: TypedListener): TRes; 21 | (eventName: string, listener: Listener): TRes; 22 | } 23 | 24 | export type MinEthersFactory = { 25 | deploy(...a: ARGS[]): Promise; 26 | }; 27 | 28 | export type GetContractTypeFromFactory = F extends MinEthersFactory ? C : never; 29 | 30 | export type GetARGsTypeFromFactory = F extends MinEthersFactory ? Parameters : never; 31 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/aave-v2/contracts/factories/AToken__factory.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | 5 | import { Contract, Signer, utils } from 'ethers'; 6 | import type { Provider } from '@ethersproject/providers'; 7 | import type { AToken, ATokenInterface } from '../AToken'; 8 | 9 | const _abi = [ 10 | { 11 | inputs: [ 12 | { 13 | internalType: 'address', 14 | name: 'user', 15 | type: 'address', 16 | }, 17 | ], 18 | name: 'scaledBalanceOf', 19 | outputs: [ 20 | { 21 | internalType: 'uint256', 22 | name: '', 23 | type: 'uint256', 24 | }, 25 | ], 26 | stateMutability: 'view', 27 | type: 'function', 28 | }, 29 | { 30 | constant: true, 31 | inputs: [], 32 | name: 'totalSupply', 33 | outputs: [ 34 | { 35 | name: '', 36 | type: 'uint256', 37 | }, 38 | ], 39 | payable: false, 40 | stateMutability: 'view', 41 | type: 'function', 42 | }, 43 | ] as const; 44 | 45 | export class AToken__factory { 46 | static readonly abi = _abi; 47 | static createInterface(): ATokenInterface { 48 | return new utils.Interface(_abi) as ATokenInterface; 49 | } 50 | static connect(address: string, signerOrProvider: Signer | Provider): AToken { 51 | return new Contract(address, _abi, signerOrProvider) as AToken; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/aave-v2/contracts/factories/ETHPriceFeed__factory.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | 5 | import { Contract, Signer, utils } from 'ethers'; 6 | import type { Provider } from '@ethersproject/providers'; 7 | import type { ETHPriceFeed, ETHPriceFeedInterface } from '../ETHPriceFeed'; 8 | 9 | const _abi = [ 10 | { 11 | inputs: [], 12 | name: 'latestAnswer', 13 | outputs: [ 14 | { 15 | internalType: 'int256', 16 | name: '', 17 | type: 'int256', 18 | }, 19 | ], 20 | stateMutability: 'view', 21 | type: 'function', 22 | }, 23 | ] as const; 24 | 25 | export class ETHPriceFeed__factory { 26 | static readonly abi = _abi; 27 | static createInterface(): ETHPriceFeedInterface { 28 | return new utils.Interface(_abi) as ETHPriceFeedInterface; 29 | } 30 | static connect(address: string, signerOrProvider: Signer | Provider): ETHPriceFeed { 31 | return new Contract(address, _abi, signerOrProvider) as ETHPriceFeed; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/aave-v2/contracts/factories/index.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | export { AToken__factory } from './AToken__factory'; 5 | export { ETHPriceFeed__factory } from './ETHPriceFeed__factory'; 6 | export { PriceOracle__factory } from './PriceOracle__factory'; 7 | export { ProtocolDataProvider__factory } from './ProtocolDataProvider__factory'; 8 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/aave-v2/contracts/index.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | export type { AToken } from './AToken'; 5 | export type { ETHPriceFeed } from './ETHPriceFeed'; 6 | export type { PriceOracle } from './PriceOracle'; 7 | export type { ProtocolDataProvider } from './ProtocolDataProvider'; 8 | export * as factories from './factories'; 9 | export { AToken__factory } from './factories/AToken__factory'; 10 | export { ETHPriceFeed__factory } from './factories/ETHPriceFeed__factory'; 11 | export { PriceOracle__factory } from './factories/PriceOracle__factory'; 12 | export { ProtocolDataProvider__factory } from './factories/ProtocolDataProvider__factory'; 13 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/aave-v2/index.ts: -------------------------------------------------------------------------------- 1 | export * from './configs'; 2 | export * from './lending-protocol'; 3 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/aave-v2/tokens/index.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | 3 | export const mainnetTokens = common.mainnetTokens; 4 | export const polygonTokens = common.polygonTokens; 5 | export const avalancheTokens = common.avalancheTokens; 6 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/aave-v3/abis/AToken.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [ 4 | { 5 | "internalType": "address", 6 | "name": "user", 7 | "type": "address" 8 | } 9 | ], 10 | "name": "scaledBalanceOf", 11 | "outputs": [ 12 | { 13 | "internalType": "uint256", 14 | "name": "", 15 | "type": "uint256" 16 | } 17 | ], 18 | "stateMutability": "view", 19 | "type": "function" 20 | } 21 | ] 22 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/aave-v3/contracts/common.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | import type { Listener } from '@ethersproject/providers'; 5 | import type { Event, EventFilter } from 'ethers'; 6 | 7 | export interface TypedEvent = any, TArgsObject = any> extends Event { 8 | args: TArgsArray & TArgsObject; 9 | } 10 | 11 | export interface TypedEventFilter<_TEvent extends TypedEvent> extends EventFilter {} 12 | 13 | export interface TypedListener { 14 | (...listenerArg: [...__TypechainArgsArray, TEvent]): void; 15 | } 16 | 17 | type __TypechainArgsArray = T extends TypedEvent ? U : never; 18 | 19 | export interface OnEvent { 20 | (eventFilter: TypedEventFilter, listener: TypedListener): TRes; 21 | (eventName: string, listener: Listener): TRes; 22 | } 23 | 24 | export type MinEthersFactory = { 25 | deploy(...a: ARGS[]): Promise; 26 | }; 27 | 28 | export type GetContractTypeFromFactory = F extends MinEthersFactory ? C : never; 29 | 30 | export type GetARGsTypeFromFactory = F extends MinEthersFactory ? Parameters : never; 31 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/aave-v3/contracts/factories/AToken__factory.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | 5 | import { Contract, Signer, utils } from 'ethers'; 6 | import type { Provider } from '@ethersproject/providers'; 7 | import type { AToken, ATokenInterface } from '../AToken'; 8 | 9 | const _abi = [ 10 | { 11 | inputs: [ 12 | { 13 | internalType: 'address', 14 | name: 'user', 15 | type: 'address', 16 | }, 17 | ], 18 | name: 'scaledBalanceOf', 19 | outputs: [ 20 | { 21 | internalType: 'uint256', 22 | name: '', 23 | type: 'uint256', 24 | }, 25 | ], 26 | stateMutability: 'view', 27 | type: 'function', 28 | }, 29 | ] as const; 30 | 31 | export class AToken__factory { 32 | static readonly abi = _abi; 33 | static createInterface(): ATokenInterface { 34 | return new utils.Interface(_abi) as ATokenInterface; 35 | } 36 | static connect(address: string, signerOrProvider: Signer | Provider): AToken { 37 | return new Contract(address, _abi, signerOrProvider) as AToken; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/aave-v3/contracts/factories/index.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | export { AToken__factory } from './AToken__factory'; 5 | export { AaveOracle__factory } from './AaveOracle__factory'; 6 | export { Pool__factory } from './Pool__factory'; 7 | export { PoolDataProvider__factory } from './PoolDataProvider__factory'; 8 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/aave-v3/contracts/index.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | export type { AToken } from './AToken'; 5 | export type { AaveOracle } from './AaveOracle'; 6 | export type { Pool } from './Pool'; 7 | export type { PoolDataProvider } from './PoolDataProvider'; 8 | export * as factories from './factories'; 9 | export { AToken__factory } from './factories/AToken__factory'; 10 | export { AaveOracle__factory } from './factories/AaveOracle__factory'; 11 | export { Pool__factory } from './factories/Pool__factory'; 12 | export { PoolDataProvider__factory } from './factories/PoolDataProvider__factory'; 13 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/aave-v3/index.ts: -------------------------------------------------------------------------------- 1 | export * from './configs'; 2 | export * from './lending-protocol'; 3 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/aave-v3/tokens/index.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | 3 | export const mainnetTokens = common.mainnetTokens; 4 | export const optimismTokens = common.optimismTokens; 5 | export const gnosisTokens = common.gnosisTokens; 6 | export const polygonTokens = common.polygonTokens; 7 | export const metisTokens = common.metisTokens; 8 | export const baseTokens = common.baseTokens; 9 | export const arbitrumTokens = common.arbitrumTokens; 10 | export const avalancheTokens = common.avalancheTokens; 11 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/compound-v3/constants.ts: -------------------------------------------------------------------------------- 1 | export const SECONDS_PER_YEAR = 60 * 60 * 24 * 365; 2 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/compound-v3/contracts/common.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | import type { Listener } from '@ethersproject/providers'; 5 | import type { Event, EventFilter } from 'ethers'; 6 | 7 | export interface TypedEvent = any, TArgsObject = any> extends Event { 8 | args: TArgsArray & TArgsObject; 9 | } 10 | 11 | export interface TypedEventFilter<_TEvent extends TypedEvent> extends EventFilter {} 12 | 13 | export interface TypedListener { 14 | (...listenerArg: [...__TypechainArgsArray, TEvent]): void; 15 | } 16 | 17 | type __TypechainArgsArray = T extends TypedEvent ? U : never; 18 | 19 | export interface OnEvent { 20 | (eventFilter: TypedEventFilter, listener: TypedListener): TRes; 21 | (eventName: string, listener: Listener): TRes; 22 | } 23 | 24 | export type MinEthersFactory = { 25 | deploy(...a: ARGS[]): Promise; 26 | }; 27 | 28 | export type GetContractTypeFromFactory = F extends MinEthersFactory ? C : never; 29 | 30 | export type GetARGsTypeFromFactory = F extends MinEthersFactory ? Parameters : never; 31 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/compound-v3/contracts/factories/index.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | export { Comet__factory } from './Comet__factory'; 5 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/compound-v3/contracts/index.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | export type { Comet } from './Comet'; 5 | export * as factories from './factories'; 6 | export { Comet__factory } from './factories/Comet__factory'; 7 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/compound-v3/index.ts: -------------------------------------------------------------------------------- 1 | export * from './configs'; 2 | export * from './lending-protocol'; 3 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/compound-v3/tokens/index.ts: -------------------------------------------------------------------------------- 1 | import * as logics from '@protocolink/logics'; 2 | 3 | export const mainnetTokens = logics.compoundv3.mainnetTokens; 4 | export const polygonTokens = logics.compoundv3.polygonTokens; 5 | export const baseTokens = logics.compoundv3.baseTokens; 6 | export const arbitrumTokens = logics.compoundv3.arbitrumTokens; 7 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/compound-v3/utils.ts: -------------------------------------------------------------------------------- 1 | import { BigNumber } from 'ethers'; 2 | import { SECONDS_PER_YEAR } from './constants'; 3 | import * as common from '@protocolink/common'; 4 | 5 | export function calcAPR(rate: BigNumber) { 6 | return common.toBigUnit(rate.mul(SECONDS_PER_YEAR), 18); 7 | } 8 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/index.ts: -------------------------------------------------------------------------------- 1 | export * as aavev2 from './aave-v2'; 2 | export * as aavev3 from './aave-v3'; 3 | export * as compoundv3 from './compound-v3'; 4 | export * as morphoblue from './morphoblue'; 5 | export * as radiantv2 from './radiant-v2'; 6 | export * as spark from './spark'; 7 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/morphoblue/abis/Oracle.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [], 4 | "name": "price", 5 | "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], 6 | "stateMutability": "view", 7 | "type": "function" 8 | } 9 | ] 10 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/morphoblue/abis/PriceFeed.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [], 4 | "name": "latestAnswer", 5 | "outputs": [ 6 | { 7 | "internalType": "int256", 8 | "name": "", 9 | "type": "int256" 10 | } 11 | ], 12 | "stateMutability": "view", 13 | "type": "function" 14 | } 15 | ] 16 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/morphoblue/configs.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | import * as logics from '@protocolink/logics'; 3 | import { mainnetTokens } from './tokens'; 4 | 5 | export const ID = 'morphoblue'; 6 | export const DISPLAY_NAME = 'Morpho'; 7 | 8 | export const loanTokenPriceFeedMap: Record> = { 9 | [common.ChainId.mainnet]: { 10 | [mainnetTokens.WETH.address]: '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419', 11 | [mainnetTokens.USDC.address]: '0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6', 12 | [mainnetTokens.USDT.address]: '0x3E7d1eAB13ad0104d2750B8863b489D65364e32D', 13 | [mainnetTokens.PYUSD.address]: '0x8f1dF6D7F2db73eECE86a18b4381F4707b918FB1', 14 | [mainnetTokens.DAI.address]: '0xAed0c38402a5d19df6E4c03F4E2DceD6e29c1ee9', 15 | [mainnetTokens.USDA.address]: '0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6', // use USDC 16 | }, 17 | }; 18 | 19 | export const supportedChainIds = logics.morphoblue.supportedChainIds; 20 | export const configMap = logics.morphoblue.configMap; 21 | export const marketMap = logics.morphoblue.marketMap; 22 | export const getContractAddress = logics.morphoblue.getContractAddress; 23 | 24 | export function getMarket(chainId: number, id: string) { 25 | const market = marketMap[chainId][id]; 26 | return { 27 | ...market, 28 | loanTokenPriceFeedAddress: loanTokenPriceFeedMap[chainId][market.loanToken.address], 29 | }; 30 | } 31 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/morphoblue/contracts/common.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | import type { Listener } from '@ethersproject/providers'; 5 | import type { Event, EventFilter } from 'ethers'; 6 | 7 | export interface TypedEvent = any, TArgsObject = any> extends Event { 8 | args: TArgsArray & TArgsObject; 9 | } 10 | 11 | export interface TypedEventFilter<_TEvent extends TypedEvent> extends EventFilter {} 12 | 13 | export interface TypedListener { 14 | (...listenerArg: [...__TypechainArgsArray, TEvent]): void; 15 | } 16 | 17 | type __TypechainArgsArray = T extends TypedEvent ? U : never; 18 | 19 | export interface OnEvent { 20 | (eventFilter: TypedEventFilter, listener: TypedListener): TRes; 21 | (eventName: string, listener: Listener): TRes; 22 | } 23 | 24 | export type MinEthersFactory = { 25 | deploy(...a: ARGS[]): Promise; 26 | }; 27 | 28 | export type GetContractTypeFromFactory = F extends MinEthersFactory ? C : never; 29 | 30 | export type GetARGsTypeFromFactory = F extends MinEthersFactory ? Parameters : never; 31 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/morphoblue/contracts/factories/Oracle__factory.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | 5 | import { Contract, Signer, utils } from 'ethers'; 6 | import type { Provider } from '@ethersproject/providers'; 7 | import type { Oracle, OracleInterface } from '../Oracle'; 8 | 9 | const _abi = [ 10 | { 11 | inputs: [], 12 | name: 'price', 13 | outputs: [ 14 | { 15 | internalType: 'uint256', 16 | name: '', 17 | type: 'uint256', 18 | }, 19 | ], 20 | stateMutability: 'view', 21 | type: 'function', 22 | }, 23 | ] as const; 24 | 25 | export class Oracle__factory { 26 | static readonly abi = _abi; 27 | static createInterface(): OracleInterface { 28 | return new utils.Interface(_abi) as OracleInterface; 29 | } 30 | static connect(address: string, signerOrProvider: Signer | Provider): Oracle { 31 | return new Contract(address, _abi, signerOrProvider) as Oracle; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/morphoblue/contracts/factories/PriceFeed__factory.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | 5 | import { Contract, Signer, utils } from 'ethers'; 6 | import type { Provider } from '@ethersproject/providers'; 7 | import type { PriceFeed, PriceFeedInterface } from '../PriceFeed'; 8 | 9 | const _abi = [ 10 | { 11 | inputs: [], 12 | name: 'latestAnswer', 13 | outputs: [ 14 | { 15 | internalType: 'int256', 16 | name: '', 17 | type: 'int256', 18 | }, 19 | ], 20 | stateMutability: 'view', 21 | type: 'function', 22 | }, 23 | ] as const; 24 | 25 | export class PriceFeed__factory { 26 | static readonly abi = _abi; 27 | static createInterface(): PriceFeedInterface { 28 | return new utils.Interface(_abi) as PriceFeedInterface; 29 | } 30 | static connect(address: string, signerOrProvider: Signer | Provider): PriceFeed { 31 | return new Contract(address, _abi, signerOrProvider) as PriceFeed; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/morphoblue/contracts/factories/index.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | export { Irm__factory } from './Irm__factory'; 5 | export { Morpho__factory } from './Morpho__factory'; 6 | export { Oracle__factory } from './Oracle__factory'; 7 | export { PriceFeed__factory } from './PriceFeed__factory'; 8 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/morphoblue/contracts/index.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | export type { Irm } from './Irm'; 5 | export type { Morpho } from './Morpho'; 6 | export type { Oracle } from './Oracle'; 7 | export type { PriceFeed } from './PriceFeed'; 8 | export * as factories from './factories'; 9 | export { Irm__factory } from './factories/Irm__factory'; 10 | export { Morpho__factory } from './factories/Morpho__factory'; 11 | export { Oracle__factory } from './factories/Oracle__factory'; 12 | export { PriceFeed__factory } from './factories/PriceFeed__factory'; 13 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/morphoblue/index.ts: -------------------------------------------------------------------------------- 1 | export * from './configs'; 2 | export * from './lending-protocol'; 3 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/morphoblue/tokens/index.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | 3 | export const mainnetTokens = common.mainnetTokens; 4 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/radiant-v2/abis/PriceOracle.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [ 4 | { 5 | "internalType": "address", 6 | "name": "asset", 7 | "type": "address" 8 | } 9 | ], 10 | "name": "getAssetPrice", 11 | "outputs": [ 12 | { 13 | "internalType": "uint256", 14 | "name": "", 15 | "type": "uint256" 16 | } 17 | ], 18 | "stateMutability": "view", 19 | "type": "function" 20 | }, 21 | { 22 | "inputs": [ 23 | { 24 | "internalType": "address[]", 25 | "name": "assets", 26 | "type": "address[]" 27 | } 28 | ], 29 | "name": "getAssetsPrices", 30 | "outputs": [ 31 | { 32 | "internalType": "uint256[]", 33 | "name": "", 34 | "type": "uint256[]" 35 | } 36 | ], 37 | "stateMutability": "view", 38 | "type": "function" 39 | } 40 | ] 41 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/radiant-v2/contracts/common.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | import type { Listener } from '@ethersproject/providers'; 5 | import type { Event, EventFilter } from 'ethers'; 6 | 7 | export interface TypedEvent = any, TArgsObject = any> extends Event { 8 | args: TArgsArray & TArgsObject; 9 | } 10 | 11 | export interface TypedEventFilter<_TEvent extends TypedEvent> extends EventFilter {} 12 | 13 | export interface TypedListener { 14 | (...listenerArg: [...__TypechainArgsArray, TEvent]): void; 15 | } 16 | 17 | type __TypechainArgsArray = T extends TypedEvent ? U : never; 18 | 19 | export interface OnEvent { 20 | (eventFilter: TypedEventFilter, listener: TypedListener): TRes; 21 | (eventName: string, listener: Listener): TRes; 22 | } 23 | 24 | export type MinEthersFactory = { 25 | deploy(...a: ARGS[]): Promise; 26 | }; 27 | 28 | export type GetContractTypeFromFactory = F extends MinEthersFactory ? C : never; 29 | 30 | export type GetARGsTypeFromFactory = F extends MinEthersFactory ? Parameters : never; 31 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/radiant-v2/contracts/factories/index.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | export { AToken__factory } from './AToken__factory'; 5 | export { PriceOracle__factory } from './PriceOracle__factory'; 6 | export { ProtocolDataProvider__factory } from './ProtocolDataProvider__factory'; 7 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/radiant-v2/contracts/index.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | export type { AToken } from './AToken'; 5 | export type { PriceOracle } from './PriceOracle'; 6 | export type { ProtocolDataProvider } from './ProtocolDataProvider'; 7 | export * as factories from './factories'; 8 | export { AToken__factory } from './factories/AToken__factory'; 9 | export { PriceOracle__factory } from './factories/PriceOracle__factory'; 10 | export { ProtocolDataProvider__factory } from './factories/ProtocolDataProvider__factory'; 11 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/radiant-v2/index.ts: -------------------------------------------------------------------------------- 1 | export * from './configs'; 2 | export * from './lending-protocol'; 3 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/radiant-v2/tokens/data/arbitrum.json: -------------------------------------------------------------------------------- 1 | { 2 | "gmETH": { 3 | "chainId": 42161, 4 | "address": "0x70d95587d40A2caf56bd97485aB3Eec10Bee6336", 5 | "decimals": 18, 6 | "symbol": "gmETH", 7 | "name": "GMX Market" 8 | }, 9 | "gmBTC": { 10 | "chainId": 42161, 11 | "address": "0x47c031236e19d024b42f8AE6780E44A573170703", 12 | "decimals": 18, 13 | "symbol": "gmBTC", 14 | "name": "GMX Market" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/radiant-v2/tokens/index.ts: -------------------------------------------------------------------------------- 1 | import arbitrumTokensJSON from './data/arbitrum.json'; 2 | import * as common from '@protocolink/common'; 3 | import * as logics from '@protocolink/logics'; 4 | 5 | export const mainnetTokens = logics.radiantv2.mainnetTokens; 6 | 7 | export const bnbTokens = common.bnbTokens; 8 | 9 | export const baseTokens = common.baseTokens; 10 | 11 | type ArbitrumTokenSymbols = keyof typeof arbitrumTokensJSON; 12 | 13 | export const arbitrumTokens = { 14 | ...common.toTokenMap(arbitrumTokensJSON), 15 | ...logics.radiantv2.arbitrumTokens, 16 | }; 17 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/spark/contracts/common.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | import type { Listener } from '@ethersproject/providers'; 5 | import type { Event, EventFilter } from 'ethers'; 6 | 7 | export interface TypedEvent = any, TArgsObject = any> extends Event { 8 | args: TArgsArray & TArgsObject; 9 | } 10 | 11 | export interface TypedEventFilter<_TEvent extends TypedEvent> extends EventFilter {} 12 | 13 | export interface TypedListener { 14 | (...listenerArg: [...__TypechainArgsArray, TEvent]): void; 15 | } 16 | 17 | type __TypechainArgsArray = T extends TypedEvent ? U : never; 18 | 19 | export interface OnEvent { 20 | (eventFilter: TypedEventFilter, listener: TypedListener): TRes; 21 | (eventName: string, listener: Listener): TRes; 22 | } 23 | 24 | export type MinEthersFactory = { 25 | deploy(...a: ARGS[]): Promise; 26 | }; 27 | 28 | export type GetContractTypeFromFactory = F extends MinEthersFactory ? C : never; 29 | 30 | export type GetARGsTypeFromFactory = F extends MinEthersFactory ? Parameters : never; 31 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/spark/contracts/factories/index.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | export { AToken__factory } from './AToken__factory'; 5 | export { AaveOracle__factory } from './AaveOracle__factory'; 6 | export { DebtTokenBase__factory } from './DebtTokenBase__factory'; 7 | export { Pool__factory } from './Pool__factory'; 8 | export { PoolAddressesProvider__factory } from './PoolAddressesProvider__factory'; 9 | export { PoolDataProvider__factory } from './PoolDataProvider__factory'; 10 | export { SparkFlashLoanCallback__factory } from './SparkFlashLoanCallback__factory'; 11 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/spark/contracts/index.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | export type { AToken } from './AToken'; 5 | export type { AaveOracle } from './AaveOracle'; 6 | export type { DebtTokenBase } from './DebtTokenBase'; 7 | export type { Pool } from './Pool'; 8 | export type { PoolAddressesProvider } from './PoolAddressesProvider'; 9 | export type { PoolDataProvider } from './PoolDataProvider'; 10 | export type { SparkFlashLoanCallback } from './SparkFlashLoanCallback'; 11 | export * as factories from './factories'; 12 | export { AaveOracle__factory } from './factories/AaveOracle__factory'; 13 | export { AToken__factory } from './factories/AToken__factory'; 14 | export { DebtTokenBase__factory } from './factories/DebtTokenBase__factory'; 15 | export { Pool__factory } from './factories/Pool__factory'; 16 | export { PoolAddressesProvider__factory } from './factories/PoolAddressesProvider__factory'; 17 | export { PoolDataProvider__factory } from './factories/PoolDataProvider__factory'; 18 | export { SparkFlashLoanCallback__factory } from './factories/SparkFlashLoanCallback__factory'; 19 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/spark/index.ts: -------------------------------------------------------------------------------- 1 | export * from './configs'; 2 | export * from './lending-protocol'; 3 | -------------------------------------------------------------------------------- /packages/lending/src/protocols/spark/tokens/index.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | 3 | export const mainnetTokens = common.mainnetTokens; 4 | export const gnosisTokens = common.gnosisTokens; 5 | -------------------------------------------------------------------------------- /packages/lending/src/swapper.ts: -------------------------------------------------------------------------------- 1 | import { SwapperQuoteFields, SwapperQuoteParams } from './swapper.type'; 2 | import * as apisdk from '@protocolink/api'; 3 | import * as common from '@protocolink/common'; 4 | import { providers } from 'ethers'; 5 | 6 | export abstract class Swapper extends common.Web3Toolkit { 7 | static readonly supportedChainIds: number[]; 8 | 9 | static isSupported(chainId: number) { 10 | return this.supportedChainIds.includes(chainId); 11 | } 12 | 13 | abstract readonly id: string; 14 | abstract readonly canCustomToken: boolean; 15 | 16 | abstract tokens(): Promise; 17 | 18 | // TODO: not implement 19 | isSupportedToken(_token: common.Token) { 20 | return true; 21 | } 22 | 23 | abstract quote(params: SwapperQuoteParams): Promise; 24 | 25 | abstract newSwapTokenLogic(fields: SwapperQuoteFields): apisdk.Logic; 26 | } 27 | 28 | export interface SwapperClass { 29 | new (chainId: number, library?: providers.Provider): Swapper; 30 | readonly supportedChainIds: number[]; 31 | isSupported: (chainId: number) => boolean; 32 | } 33 | -------------------------------------------------------------------------------- /packages/lending/src/swapper.type.ts: -------------------------------------------------------------------------------- 1 | import * as core from '@protocolink/core'; 2 | 3 | export type SwapperQuoteParams = core.TokenToTokenParams<{ slippage?: number }>; 4 | 5 | export type SwapperQuoteFields = core.TokenToTokenExactInFields<{ slippage?: number }>; 6 | -------------------------------------------------------------------------------- /packages/lending/src/swappers/index.ts: -------------------------------------------------------------------------------- 1 | export * as paraswapv5 from './paraswap-v5'; 2 | export * as openoceanv2 from './openocean-v2'; 3 | -------------------------------------------------------------------------------- /packages/lending/src/swappers/openocean-v2/configs.ts: -------------------------------------------------------------------------------- 1 | import * as common from '@protocolink/common'; 2 | import * as logics from '@protocolink/logics'; 3 | 4 | export const ID = 'openocean-v2'; 5 | 6 | export const supportedChainIds = logics.openoceanv2.SwapTokenLogic.supportedChainIds; 7 | 8 | export const disabledDexIdsMap: { [key in number]?: string } = { 9 | [common.ChainId.gnosis]: '6', // BalancerV2 10 | }; 11 | -------------------------------------------------------------------------------- /packages/lending/src/swappers/openocean-v2/index.ts: -------------------------------------------------------------------------------- 1 | export * from './configs'; 2 | export * from './lending-swapper'; 3 | -------------------------------------------------------------------------------- /packages/lending/src/swappers/openocean-v2/lending-swapper.test.ts: -------------------------------------------------------------------------------- 1 | import { LendingSwapper } from './lending-swapper'; 2 | import { SwapperQuoteParams } from 'src/swapper.type'; 3 | import * as common from '@protocolink/common'; 4 | import { expect } from 'chai'; 5 | 6 | describe('Test OpenOcean V2 LendingSwapper', function () { 7 | context('Test quote', function () { 8 | const testCases: { chainId: common.ChainId; params: SwapperQuoteParams }[] = [ 9 | { 10 | chainId: common.ChainId.metis, 11 | params: { 12 | input: new common.TokenAmount(common.metisTokens['m.DAI'], '1'), 13 | tokenOut: common.metisTokens['m.USDC'], 14 | slippage: 100, 15 | }, 16 | }, 17 | { 18 | chainId: common.ChainId.metis, 19 | params: { 20 | tokenIn: common.metisTokens['m.DAI'], 21 | output: new common.TokenAmount(common.metisTokens['m.USDC'], '1'), 22 | slippage: 100, 23 | }, 24 | }, 25 | ]; 26 | 27 | testCases.forEach(({ chainId, params }) => { 28 | it(`${common.toNetworkId(chainId)} market`, async function () { 29 | const swapper = new LendingSwapper(chainId); 30 | const fields = await swapper.quote(params); 31 | expect(fields.output.gt('0')).to.be.true; 32 | }); 33 | }); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /packages/lending/src/swappers/paraswap-v5/configs.ts: -------------------------------------------------------------------------------- 1 | import * as logics from '@protocolink/logics'; 2 | 3 | export const ID = 'paraswap-v5'; 4 | 5 | export const supportedChainIds = logics.paraswapv5.SwapTokenLogic.supportedChainIds; 6 | -------------------------------------------------------------------------------- /packages/lending/src/swappers/paraswap-v5/index.ts: -------------------------------------------------------------------------------- 1 | export * from './configs'; 2 | export * from './lending-swapper'; 3 | -------------------------------------------------------------------------------- /packages/lending/src/swappers/paraswap-v5/lending-swapper.ts: -------------------------------------------------------------------------------- 1 | import { ID, supportedChainIds } from './configs'; 2 | import { Swapper } from 'src/swapper'; 3 | import { SwapperQuoteParams } from 'src/swapper.type'; 4 | import * as apisdk from '@protocolink/api'; 5 | import * as common from '@protocolink/common'; 6 | 7 | export class LendingSwapper extends Swapper { 8 | static readonly supportedChainIds = supportedChainIds; 9 | 10 | readonly id = ID; 11 | readonly canCustomToken = false; 12 | 13 | static isSupported(chainId: number) { 14 | return this.supportedChainIds.includes(chainId); 15 | } 16 | 17 | private _tokens?: common.Token[]; 18 | 19 | async tokens() { 20 | if (!this._tokens) { 21 | this._tokens = await apisdk.protocols.paraswapv5.getSwapTokenTokenList(this.chainId); 22 | } 23 | return this._tokens; 24 | } 25 | 26 | async quote(params: SwapperQuoteParams) { 27 | return apisdk.protocols.paraswapv5.getSwapTokenQuotation(this.chainId, { ...params, excludeDEXS: ['BalancerV2'] }); 28 | } 29 | 30 | newSwapTokenLogic = apisdk.protocols.paraswapv5.newSwapTokenLogic; 31 | } 32 | -------------------------------------------------------------------------------- /packages/lending/test/hooks.ts: -------------------------------------------------------------------------------- 1 | import { Adapter } from 'src/adapter'; 2 | import { aavev2, aavev3, compoundv3, morphoblue, radiantv2, spark } from 'src/protocols'; 3 | import * as common from '@protocolink/common'; 4 | import { paraswapv5 } from 'src/swappers'; 5 | 6 | if (process.env.MAINNET_RPC_URL) { 7 | common.setNetwork(common.ChainId.mainnet, { rpcUrl: process.env.MAINNET_RPC_URL }); 8 | } 9 | 10 | export async function setup() { 11 | Adapter.registerProtocol(aavev2.LendingProtocol); 12 | Adapter.registerProtocol(aavev3.LendingProtocol); 13 | Adapter.registerProtocol(compoundv3.LendingProtocol); 14 | Adapter.registerProtocol(morphoblue.LendingProtocol); 15 | Adapter.registerProtocol(radiantv2.LendingProtocol); 16 | Adapter.registerProtocol(spark.LendingProtocol); 17 | Adapter.registerSwapper(paraswapv5.LendingSwapper); 18 | } 19 | -------------------------------------------------------------------------------- /packages/lending/test/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from './utils'; 2 | export * from './helpers'; 3 | -------------------------------------------------------------------------------- /packages/lending/test/utils/utils.ts: -------------------------------------------------------------------------------- 1 | import { BigNumber } from 'ethers'; 2 | import { expect } from 'chai'; 3 | 4 | export function expectEqWithinBps(actual: BigNumber, expected: BigNumber, bps = 1, bpsBase = 10000) { 5 | const base = BigNumber.from(bpsBase); 6 | const upper = expected.mul(base.add(BigNumber.from(bps))).div(base); 7 | const lower = expected.mul(base.sub(BigNumber.from(bps))).div(base); 8 | expect(actual).to.be.lte(upper); 9 | expect(actual).to.be.gte(lower); 10 | } 11 | -------------------------------------------------------------------------------- /packages/lending/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "dist", 5 | "declarationDir": "dist", 6 | "rootDir": "src" 7 | }, 8 | "exclude": ["test/**/*", "**/*.test.ts", "hardhat.config.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/lending/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "paths": { 6 | "src/*": ["src/*"], 7 | "test/*": ["test/*"] 8 | } 9 | }, 10 | "include": ["src/**/*", "test/**/*", "examples/**/*", "hardhat.config.ts"] 11 | } 12 | -------------------------------------------------------------------------------- /packages/smart-accounts/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # @protocolink/smart-accounts 2 | 3 | ## 0.1.8 4 | 5 | ### Patch Changes 6 | 7 | - 3b8b6eb: Update dependencies 8 | 9 | ## 0.1.7 10 | 11 | ### Patch Changes 12 | 13 | - b5076e4: Update dependencies 14 | - @protocolink/common@0.5.4 15 | 16 | ## 0.1.6 17 | 18 | ### Patch Changes 19 | 20 | - 5227a1b: Update dependencies 21 | - @protocolink/common@0.5.3 22 | 23 | ## 0.1.5 24 | 25 | ### Patch Changes 26 | 27 | - 812da9f: Update dependencies 28 | - @protocolink/common@0.5.1 29 | 30 | ## 0.1.4 31 | 32 | ### Patch Changes 33 | 34 | - 1b7b9e2: Update dependencies 35 | - @protocolink/common@0.4.2 36 | 37 | ## 0.1.3 38 | 39 | ### Patch Changes 40 | 41 | - 147cfdc: Update dependencies 42 | - @protocolink/common@0.3.11 43 | 44 | ## 0.1.2 45 | 46 | ### Patch Changes 47 | 48 | - 479f575: export config for external use 49 | 50 | ## 0.1.1 51 | 52 | ### Patch Changes 53 | 54 | - 2d25c48: The first version release for Protocolink Smart Accounts 55 | -------------------------------------------------------------------------------- /packages/smart-accounts/README.md: -------------------------------------------------------------------------------- 1 | # @protocolink/smart-accounts 2 | 3 | The smart accounts sdk for Protocolink. 4 | 5 | ## Install 6 | 7 | Install the package via `npm`: 8 | 9 | ```sh 10 | npm install @protocolink/smart-accounts 11 | ``` 12 | 13 | or `yarn`: 14 | 15 | ```sh 16 | yarn add @protocolink/smart-accounts 17 | ``` 18 | -------------------------------------------------------------------------------- /packages/smart-accounts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@protocolink/smart-accounts", 3 | "version": "0.1.8", 4 | "description": "Protocolink Smart Accounts SDK", 5 | "keywords": [ 6 | "furucombo", 7 | "protocolink" 8 | ], 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/dinngo/protocolink-js-sdk.git", 12 | "directory": "packages/smart-accounts" 13 | }, 14 | "license": "MIT", 15 | "main": "dist/index.js", 16 | "types": "dist/index.d.ts", 17 | "files": [ 18 | "dist/**/*" 19 | ], 20 | "scripts": { 21 | "build": "rm -rf dist && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json", 22 | "format": "yarn sort-package-json", 23 | "lint": "eslint --fix src", 24 | "prepublishOnly": "yarn build", 25 | "test": "mocha", 26 | "test:unit": "mocha --recursive src", 27 | "typechain": "rm -rf src/contracts && typechain --target ethers-v5 --out-dir src/contracts src/abis/*.json && pretty-quick" 28 | }, 29 | "dependencies": { 30 | "@protocolink/common": "^0.5.5", 31 | "ethers": "^5.7.2", 32 | "tiny-invariant": "^1.3.1" 33 | }, 34 | "devDependencies": { 35 | "@protocolink/test-helpers": "*" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /packages/smart-accounts/src/abis/Executor.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "constructor", 4 | "inputs": [ 5 | { 6 | "name": "router_", 7 | "type": "address", 8 | "internalType": "address" 9 | } 10 | ], 11 | "stateMutability": "nonpayable" 12 | }, 13 | { 14 | "type": "function", 15 | "name": "executeFromAgent", 16 | "inputs": [ 17 | { 18 | "name": "tos_", 19 | "type": "address[]", 20 | "internalType": "address[]" 21 | }, 22 | { 23 | "name": "datas_", 24 | "type": "bytes[]", 25 | "internalType": "bytes[]" 26 | }, 27 | { 28 | "name": "values_", 29 | "type": "uint256[]", 30 | "internalType": "uint256[]" 31 | } 32 | ], 33 | "outputs": [], 34 | "stateMutability": "nonpayable" 35 | } 36 | ] 37 | -------------------------------------------------------------------------------- /packages/smart-accounts/src/account.ts: -------------------------------------------------------------------------------- 1 | import { Executor__factory } from './contracts'; 2 | import * as configs from './configs'; 3 | 4 | export function isSupportedSmartAccountId(chainId: number, id: string) { 5 | return !!configs.getConfig(chainId) && !!configs.getSmartAccount(chainId, id); 6 | } 7 | 8 | export function encodeSmartAccount(chainId: number, id: string, tos: string[], datas: string[], values: string[]) { 9 | const smartAccount = configs.getSmartAccount(chainId, id); 10 | const to = smartAccount.executor; 11 | const data = Executor__factory.createInterface().encodeFunctionData('executeFromAgent', [tos, datas, values]); 12 | return { to, data }; 13 | } 14 | -------------------------------------------------------------------------------- /packages/smart-accounts/src/contracts/common.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | import type { Listener } from '@ethersproject/providers'; 5 | import type { Event, EventFilter } from 'ethers'; 6 | 7 | export interface TypedEvent = any, TArgsObject = any> extends Event { 8 | args: TArgsArray & TArgsObject; 9 | } 10 | 11 | export interface TypedEventFilter<_TEvent extends TypedEvent> extends EventFilter {} 12 | 13 | export interface TypedListener { 14 | (...listenerArg: [...__TypechainArgsArray, TEvent]): void; 15 | } 16 | 17 | type __TypechainArgsArray = T extends TypedEvent ? U : never; 18 | 19 | export interface OnEvent { 20 | (eventFilter: TypedEventFilter, listener: TypedListener): TRes; 21 | (eventName: string, listener: Listener): TRes; 22 | } 23 | 24 | export type MinEthersFactory = { 25 | deploy(...a: ARGS[]): Promise; 26 | }; 27 | 28 | export type GetContractTypeFromFactory = F extends MinEthersFactory ? C : never; 29 | 30 | export type GetARGsTypeFromFactory = F extends MinEthersFactory ? Parameters : never; 31 | -------------------------------------------------------------------------------- /packages/smart-accounts/src/contracts/factories/index.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | export { Executor__factory } from './Executor__factory'; 5 | -------------------------------------------------------------------------------- /packages/smart-accounts/src/contracts/index.ts: -------------------------------------------------------------------------------- 1 | /* Autogenerated file. Do not edit manually. */ 2 | /* tslint:disable */ 3 | /* eslint-disable */ 4 | export type { Executor } from './Executor'; 5 | export * as factories from './factories'; 6 | export { Executor__factory } from './factories/Executor__factory'; 7 | -------------------------------------------------------------------------------- /packages/smart-accounts/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './configs'; 2 | export * from './account'; 3 | -------------------------------------------------------------------------------- /packages/smart-accounts/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "dist", 5 | "declarationDir": "dist", 6 | "rootDir": "src" 7 | }, 8 | "exclude": ["test/**/*", "**/*.test.ts", "hardhat.config.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/smart-accounts/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "paths": { 6 | "src/*": ["src/*"] 7 | } 8 | }, 9 | "include": ["src/**/*", "test/**/*", "hardhat.config.ts"] 10 | } 11 | -------------------------------------------------------------------------------- /packages/test-helpers/.env.arbitrum: -------------------------------------------------------------------------------- 1 | CHAIN_ID=42161 2 | HTTP_RPC_URL=https://arb1.arbitrum.io/rpc 3 | -------------------------------------------------------------------------------- /packages/test-helpers/.env.mainnet: -------------------------------------------------------------------------------- 1 | CHAIN_ID=1 2 | HTTP_RPC_URL=https://rpc.ankr.com/eth 3 | -------------------------------------------------------------------------------- /packages/test-helpers/.env.polygon: -------------------------------------------------------------------------------- 1 | CHAIN_ID=137 2 | HTTP_RPC_URL=https://rpc.ankr.com/polygon 3 | -------------------------------------------------------------------------------- /packages/test-helpers/README.md: -------------------------------------------------------------------------------- 1 | # @protocolink/test-helpers 2 | 3 | The test-helpers sdk for Protocolink. 4 | 5 | ## Install 6 | 7 | Install the package via `npm`: 8 | 9 | ```sh 10 | npm install --save-dev @protocolink/test-helpers 11 | ``` 12 | 13 | or `yarn`: 14 | 15 | ```sh 16 | yarn add --dev @protocolink/test-helpers 17 | ``` 18 | -------------------------------------------------------------------------------- /packages/test-helpers/hardhat.config.ts: -------------------------------------------------------------------------------- 1 | import 'src/chai-matchers'; 2 | 3 | import config from '../../hardhat.config'; 4 | 5 | export default config; 6 | -------------------------------------------------------------------------------- /packages/test-helpers/src/chai-matchers/index.ts: -------------------------------------------------------------------------------- 1 | import './types'; 2 | 3 | import { supportChangeBalance } from './change-balance'; 4 | import { use } from 'chai'; 5 | 6 | use(function (chai, utils) { 7 | supportChangeBalance(chai.Assertion, utils); 8 | }); 9 | -------------------------------------------------------------------------------- /packages/test-helpers/src/chai-matchers/types.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-unused-vars */ 2 | /* eslint-disable @typescript-eslint/no-namespace */ 3 | 4 | declare namespace Chai { 5 | interface Assertion extends LanguageChains, NumericComparison, TypeComparison { 6 | changeBalance(token: any, balance: any, slippage?: number): AsyncAssertion; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/test-helpers/src/hooks/index.ts: -------------------------------------------------------------------------------- 1 | export * from './network'; 2 | -------------------------------------------------------------------------------- /packages/test-helpers/src/hooks/network.ts: -------------------------------------------------------------------------------- 1 | import { revert, snapshot } from 'src/utils'; 2 | 3 | export function snapshotAndRevertOnce() { 4 | before(async function () { 5 | await snapshot(); 6 | }); 7 | 8 | after(async function () { 9 | await revert(); 10 | }); 11 | } 12 | 13 | export function snapshotAndRevertEach() { 14 | beforeEach(async function () { 15 | await snapshot(); 16 | }); 17 | 18 | afterEach(async function () { 19 | await revert(); 20 | }); 21 | } 22 | -------------------------------------------------------------------------------- /packages/test-helpers/src/index.ts: -------------------------------------------------------------------------------- 1 | import './chai-matchers'; 2 | 3 | export * from './hooks'; 4 | export * from './utils'; 5 | -------------------------------------------------------------------------------- /packages/test-helpers/src/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from './faucet'; 2 | export * from './network'; 3 | export * from './web3'; 4 | -------------------------------------------------------------------------------- /packages/test-helpers/src/utils/network.ts: -------------------------------------------------------------------------------- 1 | export async function getChainId() { 2 | const hre = await import('hardhat'); 3 | const network = await hre.ethers.provider.getNetwork(); 4 | return network.chainId; 5 | } 6 | 7 | let snapshotId: string; 8 | 9 | export async function snapshot() { 10 | const hre = await import('hardhat'); 11 | snapshotId = await hre.network.provider.send('evm_snapshot', []); 12 | } 13 | 14 | export async function revert() { 15 | const hre = await import('hardhat'); 16 | await hre.network.provider.send('evm_revert', [snapshotId]); 17 | } 18 | -------------------------------------------------------------------------------- /packages/test-helpers/src/utils/web3.ts: -------------------------------------------------------------------------------- 1 | import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; 2 | import * as common from '@protocolink/common'; 3 | import { constants, providers } from 'ethers'; 4 | import { expect } from 'chai'; 5 | import { getChainId } from './network'; 6 | 7 | export async function getBalance( 8 | account: string, 9 | tokenOrAddress: common.TokenOrAddress, 10 | blockTag?: providers.BlockTag 11 | ) { 12 | const hre = await import('hardhat'); 13 | const chainId = await getChainId(); 14 | 15 | const web3Toolkit = new common.Web3Toolkit(chainId, hre.ethers.provider); 16 | const balance = await web3Toolkit.getBalance(account, tokenOrAddress, blockTag); 17 | 18 | return balance; 19 | } 20 | 21 | export async function approve(user: SignerWithAddress, spender: string, tokenAmount: common.TokenAmount) { 22 | if (tokenAmount.token.isNative) return; 23 | 24 | const erc20 = common.ERC20__factory.connect(tokenAmount.token.address, user); 25 | const allowance = await erc20.allowance(user.address, spender); 26 | if (allowance.gte(tokenAmount.amountWei)) return; 27 | await expect(erc20.approve(spender, constants.MaxUint256)).not.to.be.reverted; 28 | } 29 | 30 | export async function approves(user: SignerWithAddress, spender: string, tokenAmounts: common.TokenAmounts) { 31 | return Promise.all(tokenAmounts.map((tokenAmount) => approve(user, spender, tokenAmount))); 32 | } 33 | -------------------------------------------------------------------------------- /packages/test-helpers/test/common/network.test.ts: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import { getChainId } from 'src/utils/network'; 3 | 4 | describe('common: Network', function () { 5 | it('Test getChainId', async function () { 6 | const chainIdFromEnv = Number(process.env.CHAIN_ID); 7 | expect(chainIdFromEnv).to.be.gt(0); 8 | const chainId = await getChainId(); 9 | expect(chainId).to.eq(chainIdFromEnv); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /packages/test-helpers/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "dist", 5 | "declarationDir": "dist", 6 | "rootDir": "src", 7 | "types": ["@nomicfoundation/hardhat-chai-matchers"] 8 | }, 9 | "exclude": ["test/**/*", "**/*.test.ts", "hardhat.config.ts"] 10 | } 11 | -------------------------------------------------------------------------------- /packages/test-helpers/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "paths": { 6 | "src/*": ["src/*"] 7 | } 8 | }, 9 | "include": ["src/**/*", "test/**/*", "hardhat.config.ts"] 10 | } 11 | -------------------------------------------------------------------------------- /tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2018", 4 | "module": "commonjs", 5 | "alwaysStrict": true, 6 | "declaration": true, 7 | "esModuleInterop": true, 8 | "forceConsistentCasingInFileNames": true, 9 | "importHelpers": true, 10 | "moduleResolution": "node", 11 | "noFallthroughCasesInSwitch": true, 12 | "noImplicitAny": true, 13 | "noImplicitReturns": true, 14 | "noImplicitThis": true, 15 | "resolveJsonModule": true, 16 | "skipLibCheck": true, 17 | "sourceMap": true, 18 | "strict": true, 19 | "strictFunctionTypes": true, 20 | "strictNullChecks": true, 21 | "strictPropertyInitialization": true, 22 | "experimentalDecorators": true 23 | }, 24 | "exclude": ["node_modules/**/*", "dist/**/*"], 25 | "ts-node": { 26 | "require": ["tsconfig-paths/register"] 27 | } 28 | } 29 | --------------------------------------------------------------------------------