From 6bf53778b3d92f629f3c783a05d11f0a4db2ffb0 Mon Sep 17 00:00:00 2001 From: microHoffman Date: Thu, 24 Apr 2025 02:58:52 +0200 Subject: [PATCH] feat: add celo, ink and linea chains support --- packages/core/project.json | 10 +++++++ packages/core/src/addresses.test.ts | 7 +++++ packages/core/src/addresses.ts | 26 ++++++++++++++++++- packages/core/src/chains.ts | 3 +++ .../v1-core/src/actions/make-proposal.test.ts | 6 +++++ packages/v1-core/src/addresses.ts | 24 +++++++++++------ packages/v1-core/src/utils/chainlink-feeds.ts | 17 +++++++++++- 7 files changed, 83 insertions(+), 10 deletions(-) diff --git a/packages/core/project.json b/packages/core/project.json index 66f0e985..4fc08b8e 100644 --- a/packages/core/project.json +++ b/packages/core/project.json @@ -7,6 +7,16 @@ "sdk-core" ], "targets": { + "type-check": { + "executor": "@nx/js:tsc", + "options": { + "main": "packages/core/src/index.ts", + "tsConfig": "packages/core/tsconfig.lib.json", + "outputPath": "packages/core/dist", + "clean": true, + "noEmit": true + } + }, "biome-lint": { "executor": "@gitopslovers/nx-biome:biome-lint", "outputs": [ diff --git a/packages/core/src/addresses.test.ts b/packages/core/src/addresses.test.ts index 035e937b..d7874a7e 100644 --- a/packages/core/src/addresses.test.ts +++ b/packages/core/src/addresses.test.ts @@ -32,6 +32,13 @@ describe("Addresses", () => { [SupportedChain.World, "0xc0aCA216Aa936511b24Ff238F610B02bE54e10AD"], [SupportedChain.Bsc, "0x4A75a527E97d853109aA6998a2B9E45a87A31e9f"], [SupportedChain.Cronos, "0x973E09e96E64E4bf17e383a8A497Fb566284c707"], + [SupportedChain.Ink, "0x490040E1A2df842Cab527146a20534e23DcC46FF"], + [SupportedChain.Linea, "0xbe13866797bbdE2646FFBb58F102FcA91EFC88F1"], + [SupportedChain.Celo, "0xf2e389cEbA01db96e9bd63B5a9Fa47422dAeEb40"], + [SupportedChain.Sepolia, "0x448E3D0a4BAa00FE511a03E7B27177AeDE6d9636"], + [SupportedChain.Unichain, "0x354869495Fd916ADAFc0626C3d60115240dc06f1"], + [SupportedChain.UnichainSepolia, "0x1381F509f56f2aaA0faBD3012455901eA53F0BbD"], + // note: no starknet version of tokenBundlerContract ])("should resolve correct bundler address for %s", (chain, expected) => { expect( CHAIN_TO_ADDRESSES_MAP[chain as V1_3_SUPPORTED_CHAINS] diff --git a/packages/core/src/addresses.ts b/packages/core/src/addresses.ts index d270190c..84b41dbc 100644 --- a/packages/core/src/addresses.ts +++ b/packages/core/src/addresses.ts @@ -139,7 +139,7 @@ const UNICHAIN_CONSTANTS: V1_3_Contracts = { // Sepolia contracts const SEPOLIA_CONTRACTS: V1_3_Contracts = { ...PWN_V1_3_CONTRACTS, - tokenBundlerContract: "0x448E3D0a4BAa0A0FE511a03E7B27177AeDE6d9636", + tokenBundlerContract: "0x448E3D0a4BAa00FE511a03E7B27177AeDE6d9636", pwnSimpleLoanElasticChainlinkProposal: "0xC46170F43b97faE1A8B507d6fdDaFfBb7527D61B", }; @@ -150,6 +150,27 @@ const UNICHAIN_SEPOLIA_CONTRACTS: V1_3_Contracts = { pwnSimpleLoanElasticChainlinkProposal: ZERO_ADDRESS, // not deployed }; +// Ink contracts +const INK_CONTRACTS: V1_3_Contracts = { + ...PWN_V1_3_CONTRACTS, + tokenBundlerContract: "0x490040E1A2df842Cab527146a20534e23DcC46FF", + pwnSimpleLoanElasticChainlinkProposal: ZERO_ADDRESS, // not deployed +}; + +// Linea contracts +const LINEA_CONTRACTS: V1_3_Contracts = { + ...PWN_V1_3_CONTRACTS, + tokenBundlerContract: "0xbe13866797bbdE2646FFBb58F102FcA91EFC88F1", + pwnSimpleLoanElasticChainlinkProposal: "0x8E9955B34606f601491c14d5cc8247F5E0477ff1", +}; + +// Celo contracts +const CELO_CONTRACTS: V1_3_Contracts = { + ...PWN_V1_3_CONTRACTS, + tokenBundlerContract: "0xf2e389cEbA01db96e9bd63B5a9Fa47422dAeEb40", + pwnSimpleLoanElasticChainlinkProposal: "0x53fb85416cAeEE7f4d142F88685e2094f6E9E985", +}; + const STARKNET_CONTRACTS: V1_2_StarknetContracts = { ...PWN_V1_2_STARKNET_CONTRACTS, }; @@ -176,6 +197,9 @@ export const V1_3_CHAIN_TO_ADDRESSES_MAP: Record< [SupportedChain.World]: WORLDCHAIN_CONTRACTS, [SupportedChain.Bsc]: BSC_CONTRACTS, [SupportedChain.Cronos]: CRONOS_CONTRACTS, + [SupportedChain.Celo]: CELO_CONTRACTS, + [SupportedChain.Linea]: LINEA_CONTRACTS, + [SupportedChain.Ink]: INK_CONTRACTS, [SupportedChain.Sepolia]: SEPOLIA_CONTRACTS, [SupportedChain.UnichainSepolia]: UNICHAIN_SEPOLIA_CONTRACTS, diff --git a/packages/core/src/chains.ts b/packages/core/src/chains.ts index caa14922..6352bf22 100644 --- a/packages/core/src/chains.ts +++ b/packages/core/src/chains.ts @@ -14,6 +14,9 @@ export enum SupportedChain { StarknetSepolia = 11155112, StarknetMainnet = 112211, World = 480, + Linea = 59144, + Celo = 42220, + Ink = 57073, } export const ALL_SUPPORTED_CHAINS = Object.values(SupportedChain).filter( diff --git a/packages/v1-core/src/actions/make-proposal.test.ts b/packages/v1-core/src/actions/make-proposal.test.ts index f18991b7..fa0b3c0e 100644 --- a/packages/v1-core/src/actions/make-proposal.test.ts +++ b/packages/v1-core/src/actions/make-proposal.test.ts @@ -53,6 +53,7 @@ describe("Test make proposal", () => { getCollateralAmount: vi.fn().mockImplementation(() => 0n), createOnChainProposal: vi.fn().mockImplementation((p) => p), getProposalHash: vi.fn().mockImplementation(() => "0x123"), + createMultiProposal: vi.fn().mockImplementation((p) => p), }; const loanContractMock = { @@ -89,6 +90,7 @@ describe("Test make proposal", () => { minCreditAmountPercentage: 3, relatedStrategyId: "1", isOffer: true, + sourceOfFunds: user_address, }, { api: { @@ -146,6 +148,7 @@ describe("Test make proposal", () => { getCollateralAmount: vi.fn().mockImplementation(() => 0n), createOnChainProposal: vi.fn().mockImplementation((p) => p), getProposalHash: vi.fn().mockImplementation(() => "0x123"), + createMultiProposal: vi.fn().mockImplementation((p) => p), }; const loanContractMock = { @@ -186,6 +189,7 @@ describe("Test make proposal", () => { minCreditAmountPercentage: 3, relatedStrategyId: "1", isOffer: true, + sourceOfFunds: user_address, }, { api: { @@ -262,6 +266,7 @@ describe("Test make proposal", () => { getCollateralAmount: vi.fn().mockImplementation(() => 0n), createOnChainProposal: vi.fn().mockImplementation((p) => p), getProposalHash: vi.fn().mockImplementation(() => "0x123"), + createMultiProposal: vi.fn().mockImplementation((p) => p), }; const poolTokenAddress = generateAddress(); @@ -311,6 +316,7 @@ describe("Test make proposal", () => { minCreditAmountPercentage: 3, relatedStrategyId: "1", isOffer: true, + sourceOfFunds: user_address, }, { api: { diff --git a/packages/v1-core/src/addresses.ts b/packages/v1-core/src/addresses.ts index 99b9bb02..75ed21e9 100644 --- a/packages/v1-core/src/addresses.ts +++ b/packages/v1-core/src/addresses.ts @@ -58,20 +58,23 @@ export const ezETH = defineAddresses({ [SupportedChain.Ethereum]: "0xbf5495efe5db9ce00f80364c8b423567e58d2110", [SupportedChain.Base]: "0x2416092f143378750bb29b79ed961ab195cceea5", [SupportedChain.Arbitrum]: "0x2416092f143378750bb29b79eD961ab195CcEea5", - [SupportedChain.Bsc]: "0x2416092f143378750bb29b79ed961ab195cceea5" + [SupportedChain.Bsc]: "0x2416092f143378750bb29b79ed961ab195cceea5", + [SupportedChain.Linea]: "0x2416092f143378750bb29b79eD961ab195CcEea5" }) export const rsETH = defineAddresses({ [SupportedChain.Ethereum]: "0xa1290d69c65a6fe4df752f95823fae25cb99e5a7", [SupportedChain.Optimism]: "0x4186BFC76E2E237523CBC30FD220FE055156b41F", - [SupportedChain.Arbitrum]: "0x4186BFC76E2E237523CBC30FD220FE055156b41F" + [SupportedChain.Arbitrum]: "0x4186BFC76E2E237523CBC30FD220FE055156b41F", + [SupportedChain.Linea]: "0x4186bfc76e2e237523cbc30fd220fe055156b41f" }) export const weETH = defineAddresses({ [SupportedChain.Ethereum]: "0xcd5fe23c85820f7b72d0926fc9b05b43e359b7ee", [SupportedChain.Base]: "0x04c0599ae5a44757c0af6f9ec3b93da8976c150a", [SupportedChain.Optimism]: "0x5A7fACB970D094B6C7FF1df0eA68D99E6e73CBFF", - [SupportedChain.Arbitrum]: "0x35751007a407ca6FEFfE80b3cB397736D2cf4dbe" + [SupportedChain.Arbitrum]: "0x35751007a407ca6FEFfE80b3cB397736D2cf4dbe", + [SupportedChain.Linea]: "0x1Bf74C010E6320bab11e2e5A532b5AC15e0b8aA6" }) export const DAI = defineAddresses({ @@ -82,7 +85,8 @@ export const DAI = defineAddresses({ [SupportedChain.Optimism]: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1", [SupportedChain.Arbitrum]: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1", [SupportedChain.Polygon]: "0x8f3cf7ad23cd3cadbd9735aff958023239c6a063", - [SupportedChain.Bsc]: "0x1af3f329e8be154074d8769d1ffa4ee058b1dbc3" + [SupportedChain.Bsc]: "0x1af3f329e8be154074d8769d1ffa4ee058b1dbc3", + [SupportedChain.Linea]: "0x4AF15ec2A0BD43Db75dd04E62FAA3B8EF36b00d5" }) export const TUSD = defineAddresses({ @@ -101,7 +105,8 @@ export const USDC = defineAddresses({ [SupportedChain.Optimism]: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85", [SupportedChain.Arbitrum]: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", [SupportedChain.Polygon]: "0x3c499c542cef5e3811e1192ce70d8cc03d5c3359", - [SupportedChain.Bsc]: "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d" + [SupportedChain.Bsc]: "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d", + [SupportedChain.Linea]: "0x176211869cA2b568f2A7D4EE941E073a821EE1ff" }) export const USDT = defineAddresses({ @@ -111,7 +116,8 @@ export const USDT = defineAddresses({ [SupportedChain.Optimism]: "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58", [SupportedChain.Arbitrum]: "0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9", [SupportedChain.Polygon]: "0xc2132d05d31c914a87c6611c10748aeb04b58e8f", - [SupportedChain.Bsc]: "0x524bc91dc82d6b90ef29f76a3ecaabafffd490bc" + [SupportedChain.Bsc]: "0x524bc91dc82d6b90ef29f76a3ecaabafffd490bc", + [SupportedChain.Linea]: "0xA219439258ca9da29E9Cc4cE5596924745e12B93" }) export const tBTC = defineAddresses({ @@ -127,7 +133,8 @@ export const wstETH = defineAddresses({ [SupportedChain.Optimism]: "0x1F32b1c2345538c0c6f582fCB022739c4A194Ebb", [SupportedChain.Arbitrum]: "0x5979D7b546E38E414F7E9822514be443A4800529", [SupportedChain.Polygon]: "0x03b54a6e9a984069379fae1a4fc4dbae93b3bccd", - [SupportedChain.Bsc]: "0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C" + [SupportedChain.Bsc]: "0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C", + [SupportedChain.Linea]: "0xB5beDd42000b71FddE22D3eE8a79Bd49A568fC8F" }) export const USD0 = defineAddresses({ @@ -150,7 +157,8 @@ export const WETH = defineAddresses({ [SupportedChain.Optimism]: "0x4200000000000000000000000000000000000006", [SupportedChain.Arbitrum]: "0x82af49447d8a07e3bd95bd0d56f35241523fbab1", [SupportedChain.Polygon]: "0x7ceb23fd6bc0add59e62ac25578270cff1b9f619", - [SupportedChain.Bsc]: "0x4db5a66e937a9f4473fa95b1caf1d1e1d62e29ea" + [SupportedChain.Bsc]: "0x4db5a66e937a9f4473fa95b1caf1d1e1d62e29ea", + [SupportedChain.Linea]: "0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f" }) export const sUSDe = defineAddresses({ diff --git a/packages/v1-core/src/utils/chainlink-feeds.ts b/packages/v1-core/src/utils/chainlink-feeds.ts index d735f8d1..bdce78f5 100644 --- a/packages/v1-core/src/utils/chainlink-feeds.ts +++ b/packages/v1-core/src/utils/chainlink-feeds.ts @@ -45,6 +45,7 @@ export const NATIVE_PAIRS = { [SupportedChain.Arbitrum]: ["BTC/ETH", "BTC/USD", "ETH/USD"], [SupportedChain.Polygon]: ["BTC/ETH", "BTC/USD", "ETH/USD"], [SupportedChain.Bsc]: ["BTC/ETH", "BTC/USD", "ETH/USD"], + [SupportedChain.Linea]: ["BTC/USD", "ETH/USD"], } as const; export const CHAINS_WITH_CHAINLINK_FEED_SUPPORT = @@ -73,7 +74,9 @@ export type AllowedQuotes = ? "ETH" | "USD" : T extends SupportedChain.Bsc ? "BTC" | "ETH" | "USD" - : never; + : T extends SupportedChain.Linea + ? "BTC" | "ETH" | "USD" + : never; // Define a type for the native pairs type NativePair = `${NativeAssetName}/${NativeAssetName}`; @@ -275,6 +278,18 @@ export const FEED_REGISTRY = { // as for ETH in NATIVE_PAIRS [WETH[SupportedChain.Sepolia]]: ["ETH", "USD"], }, + [SupportedChain.Linea]: { + [rsETH[SupportedChain.Linea]]: ["ETH"], + [ezETH[SupportedChain.Linea]]: ["ETH"], + [weETH[SupportedChain.Linea]]: ["ETH"], + [wstETH[SupportedChain.Linea]]: ["USD"], + [DAI[SupportedChain.Linea]]: ["USD"], + [USDC[SupportedChain.Linea]]: ["USD"], + [USDT[SupportedChain.Linea]]: ["USD"], + // note: slight hack as WETH == ETH, so these are the same feeds + // as for ETH in NATIVE_PAIRS + [WETH[SupportedChain.Linea]]: ["ETH", "USD"], + }, } as const satisfies CompleteFeedRegistry; export const convertNameIntoDenominator = <