diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..99580d0 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8fa97e8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*.retry +.DS_Store +*.local.* + +node_modules + +/generated +_tmp + diff --git a/conf/mainnets/$.yml b/conf/mainnets/$.yml new file mode 100644 index 0000000..87f3eac --- /dev/null +++ b/conf/mainnets/$.yml @@ -0,0 +1,8 @@ + +protocol: + lnv2-default: '0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337' + lnv2-opposite: '0x48d769d5C7ff75703cDd1543A1a2ed9bC9044A23' + lnv3: '0xbA5D580B18b6436411562981e02c8A9aA1776D10' +messagers: + - name: msgline + address: '0x65Be094765731F394bc6d9DF53bDF3376F1Fc8B0' diff --git a/conf/mainnets/arbitrum.yml b/conf/mainnets/arbitrum.yml new file mode 100644 index 0000000..bfabee1 --- /dev/null +++ b/conf/mainnets/arbitrum.yml @@ -0,0 +1,132 @@ +id: "42161" +code: arbitrum +name: Arbitrum +rpcs: + - https://polygon-bor-rpc.publicnode.com +protocol: + lnv2-default: '0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337' + lnv2-opposite: '0x48d769d5C7ff75703cDd1543A1a2ed9bC9044A23' + lnv3: '0xbA5D580B18b6436411562981e02c8A9aA1776D10' +messagers: + - name: layerzero + address: '0x509354A4ebf98aCC7a65d2264694A65a2938cac9' +tokens: + - symbol: ETH + address: '0x0000000000000000000000000000000000000000' + decimals: 18 + type: native + - symbol: USDT + address: '0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9' + decimals: 6 + type: erc20 + - symbol: USDC + address: '0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8' + decimals: 6 + type: erc20 + - symbol: RING + address: '0x9e523234D36973f9e38642886197D023C88e307e' + decimals: 18 + type: erc20 +couples: + + ## eth + - chain: blast + symbol: eth + protocol: lnv3 + fee: '10000000000000' + messager: layerzero + - chain: linea + symbol: eth + protocol: lnv2-default + fee: '10000000000000' + messager: layerzero + - chain: astar-zkevm + symbol: eth + protocol: lnv3 + fee: '10000000000000' + messager: layerzero + - chain: op + symbol: eth + protocol: lnv3 + fee: '10000000000000' + messager: layerzero + + + ## ring + - chain: ethereum + symbol: + from: RING + to: RING + protocol: lnv2-opposite + fee: '100000000000000000000' + messager: arbitrum-l2 + - chain: polygon + symbol: RING + protocol: lnv2-default + fee: '100000000000000000000' + messager: layerzero + - chain: darwinia-dvm + symbol: RING/RING + protocol: lnv2-default + fee: '10000000000000000000' + messager: msgline + + ## usdt + - chain: mantle + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: zksync + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: bsc + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: linea + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: polygon + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: op + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: gnosis + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: scroll + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: moonbeam + symbol: USDT + protocol: lnv3 + fee: '100000' + messager: layerzero + + ## usdc + - chain: mantle + symbol: USDC + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: scroll + symbol: USDC + protocol: lnv2-default + fee: '100000' + messager: layerzero + diff --git a/conf/mainnets/astar-zkevm.yml b/conf/mainnets/astar-zkevm.yml new file mode 100644 index 0000000..2afbe76 --- /dev/null +++ b/conf/mainnets/astar-zkevm.yml @@ -0,0 +1,22 @@ +id: "3776" +code: astar-zkevm +name: Astar zkEVM +rpcs: + - https://rpc.startale.com/astar-zkevm +messagers: + - name: layerzero + address: '0x61B6B8c7C00aA7F060a2BEDeE6b11927CC9c3eF1' +tokens: + - symbol: 'eth' + address: '0x0000000000000000000000000000000000000000' + decimals: 18 + type: native +couples: + + ## eth + - chain: arbitrum + symbol: eth + protocol: lnv3 + fee: '10000000000000' + messager: layerzero + diff --git a/conf/mainnets/base.yml b/conf/mainnets/base.yml new file mode 100644 index 0000000..5d098d0 --- /dev/null +++ b/conf/mainnets/base.yml @@ -0,0 +1,22 @@ +id: "8453" +code: base +name: base +rpcs: + - https://mainnet.base.org +tokens: + - symbol: 'eth' + address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913' + decimals: 18 + type: native + - symbol: 'usdc' + address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913' + decimals: 6 + type: erc20 + +couples: + ## usdc + - chain: bsc + symbol: usdc + protocol: lnv2-default + fee: '100000' + messager: layerzero diff --git a/conf/mainnets/blast.yml b/conf/mainnets/blast.yml new file mode 100644 index 0000000..5db6b56 --- /dev/null +++ b/conf/mainnets/blast.yml @@ -0,0 +1,19 @@ +id: "81457" +code: blast +name: Blast +rpcs: + - https://rpc.blastblockchain.com +tokens: + - symbol: 'eth' + address: '0x0000000000000000000000000000000000000000' + decimals: 18 + type: native + +couples: + ## eth + - chain: arbitrum + symbol: eth + protocol: lnv3 + fee: '10000000000000' + messager: layerzero + diff --git a/conf/mainnets/bsc.yml b/conf/mainnets/bsc.yml new file mode 100644 index 0000000..0772d6f --- /dev/null +++ b/conf/mainnets/bsc.yml @@ -0,0 +1,76 @@ +id: "56" +code: bsc +name: bsc +rpcs: + - https://bsc-rpc.publicnode.com +messagers: + - name: layerzero + address: '0x89AF830781A2C1d3580Db930bea11094F55AfEae' +tokens: + - symbol: bnb + address: '0x0000000000000000000000000000000000000000' + decimals: 18 + type: native + - symbol: usdt + address: '0x55d398326f99059fF775485246999027B3197955' + decimals: 18 + type: erc20 + - symbol: usdc + address: '0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d' + decimals: 18 + type: erc20 + +couples: + + ## usdt + - chain: arbitrum + symbol: usdt + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + - chain: op + symbol: usdt + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + - chain: linea + symbol: usdt + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + - chain: polygon + symbol: usdt + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + - chain: polygon-zkEvm + symbol: usdt + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + - chain: mantle + symbol: usdt + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + - chain: scroll + symbol: usdt + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + - chain: gnosis + symbol: usdt + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + + + ## usdc + - chain: base + symbol: usdc + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + + + diff --git a/conf/mainnets/crab.yml b/conf/mainnets/crab.yml new file mode 100644 index 0000000..f4e75eb --- /dev/null +++ b/conf/mainnets/crab.yml @@ -0,0 +1,38 @@ +id: "44" +code: crab-dvm +name: Crab +rpcs: + - https://crab-rpc.darwinia.network +tokens: + - symbol: crab + address: '0x0000000000000000000000000000000000000000' + decimals: 18 + type: native + - symbol: ring + address: '0x273131F7CB50ac002BDd08cA721988731F7e1092' + decimals: 18 + type: erc20 + - symbol: xWRING + name: xWRING + address: '0x273131F7CB50ac002BDd08cA721988731F7e1092' + decimals: 18 + type: erc20 + +couples: + + ## crab + - chain: darwinia-dvm + symbol: crab/xWCRAB + protocol: lnv2-default + fee: '100000000000000000000' + messager: msgline + hidden: true + + - chain: darwinia-dvm + symbol: xWRING/ring + protocol: lnv2-default + fee: '10000000000000000000' + messager: msgline + category: ring + hidden: true + diff --git a/conf/mainnets/darwinia.yml b/conf/mainnets/darwinia.yml new file mode 100644 index 0000000..9fd48c1 --- /dev/null +++ b/conf/mainnets/darwinia.yml @@ -0,0 +1,81 @@ +id: "46" +code: darwinia-dvm +name: Darwinia +rpcs: + - https://rpc.darwinia.network +tokens: + - symbol: ring + address: '0x0000000000000000000000000000000000000000' + decimals: 18 + type: native + - symbol: crab + address: '0x656567Eb75b765FC320783cc6EDd86bD854b2305' + decimals: 18 + type: erc20 + - symbol: xWCRAB + name: xWCRAB + address: '0x656567Eb75b765FC320783cc6EDd86bD854b2305' + decimals: 18 + type: erc20 + - symbol: ahPINK + name: ahPINK + address: '0x0000000000000000000000000000000000000404' + decimals: 10 + type: erc20 + - symbol: ahUSDT + name: ahUSDT + address: '0x0000000000000000000000000000000000000403' + decimals: 6 + type: erc20 + +couples: + + ## ring + - chain: arbitrum + symbol: ring + protocol: lnv2-default + fee: '100000000000000000000' + messager: msgline + - chain: ethereum + symbol: ring + protocol: lnv2-opposite + fee: '100000000000000000000' + messager: msgline + - chain: crab-dvm + symbol: ring/xWRING + protocol: lnv2-default + fee: '100000000000000000000' + messager: msgline + hidden: true + - chain: polygon + symbol: ring + protocol: lnv3 + fee: '100000000000000000000' + messager: msgline + + ## crab + - chain: crab-dvm + symbol: xWCRAB/crab + protocol: lnv2-default + fee: '100000000000000000000' + messager: msgline + category: crab + hidden: true + + ## ahUSDT + - chain: moonbeam + symbol: ahUSDT/xcUSDT + protocol: lnv3 + fee: '1000' + messager: msgline + category: usdt + + ## ahPINK + - chain: moonbeam + symbol: ahPINK/xcPINK + protocol: lnv3 + fee: '10000000' + messager: msgline + category: pink + + diff --git a/conf/mainnets/ethereum.yml b/conf/mainnets/ethereum.yml new file mode 100644 index 0000000..b11e165 --- /dev/null +++ b/conf/mainnets/ethereum.yml @@ -0,0 +1,28 @@ +id: "1" +code: ethereum +name: Ethereum +rpcs: + - https://ethereum-rpc.publicnode.com +tokens: + - symbol: ring + address: '0x0000000000000000000000000000000000000000' + decimals: 18 + type: native + - symbol: ring + address: '0x9469D013805bFfB7D3DEBe5E7839237e535ec483' + decimals: 18 + type: erc20 +couples: + + ## ring + - chain: arbitrum + symbol: RING + protocol: lnv2-default + fee: '100000000000000000000' + messager: arbitrum-l2 + - chain: darwinia-dvm + symbol: RING + protocol: lnv2-default + fee: '100000000000000000000' + messager: msgline + diff --git a/conf/mainnets/gnosis.yml b/conf/mainnets/gnosis.yml new file mode 100644 index 0000000..3caf85c --- /dev/null +++ b/conf/mainnets/gnosis.yml @@ -0,0 +1,56 @@ +id: "100" +code: gnosis +name: Gnosis +rpcs: + - https://gnosis-rpc.publicnode.com +messagers: + - name: layerzero + address: '0x3F7DF5866591e7E48D18C8EbeAE61Bc343a63283' +tokens: + - symbol: xDai + name: xDai + address: '0x0000000000000000000000000000000000000000' + decimals: 18 + type: native + - symbol: usdt + address: '0x4ECaBa5870353805a9F068101A40E0f32ed605C6' + decimals: 6 + type: erc20 +couples: + + ## usdt + - chain: bsc + symbol: USDT + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + - chain: polygon + symbol: USDT + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + - chain: linea + symbol: USDT + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + - chain: op + symbol: USDT + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + - chain: mantle + symbol: USDT + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + - chain: scroll + symbol: USDT + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + - chain: arbitrum + symbol: USDT + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero diff --git a/conf/mainnets/linea.yml b/conf/mainnets/linea.yml new file mode 100644 index 0000000..ed1751d --- /dev/null +++ b/conf/mainnets/linea.yml @@ -0,0 +1,62 @@ +id: "59144" +code: linea +name: Linea +rpcs: + - https://linea.decubate.com +messagers: + - name: layerzero + address: '0x61B6B8c7C00aA7F060a2BEDeE6b11927CC9c3eF1' +tokens: + - symbol: 'eth' + address: '0x0000000000000000000000000000000000000000' + decimals: 18 + type: native + - symbol: 'usdt' + address: '0xA219439258ca9da29E9Cc4cE5596924745e12B93' + decimals: 6 + type: erc20 +couples: + ## eth + - chain: arbitrum + symbol: eth + protocol: lnv2-default + fee: '10000000000000' + messager: layerzero + + ## usdt + - chain: arbitrum + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: bsc + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: polygon + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: op + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: mantle + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: scroll + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: gnosis + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + diff --git a/conf/mainnets/mantle.yml b/conf/mainnets/mantle.yml new file mode 100644 index 0000000..ce6f588 --- /dev/null +++ b/conf/mainnets/mantle.yml @@ -0,0 +1,82 @@ +id: "5000" +code: mantle +name: Mantle +rpcs: + - https://mantle-rpc.publicnode.com +messagers: + - name: layerzero + address: '0x61B6B8c7C00aA7F060a2BEDeE6b11927CC9c3eF1' +tokens: + - symbol: MNT + address: '0x0000000000000000000000000000000000000000' + decimals: 6 + type: native + - symbol: usdt + address: '0x201EBa5CC46D216Ce6DC03F6a759e8E766e956aE' + decimals: 6 + type: erc20 + - symbol: usdc + address: '0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9' + decimals: 6 + type: erc20 +couples: + + # usdt + - chain: arbitrum + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: zksync + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: scroll + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: scroll + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: bsc + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: linea + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: op + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: polygon + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: gnosis + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + + + ## usdc + - chain: arbitrum + symbol: USDC + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: scroll + symbol: USDC + protocol: lnv2-default + fee: '100000' + messager: layerzero diff --git a/conf/mainnets/moonbeam.yml b/conf/mainnets/moonbeam.yml new file mode 100644 index 0000000..ffad8de --- /dev/null +++ b/conf/mainnets/moonbeam.yml @@ -0,0 +1,51 @@ +id: "1284" +code: moonbeam +name: Moonbeam +rpcs: + - https://moonbeam-rpc.dwellir.com +messagers: + - name: layerzero + address: '0x61B6B8c7C00aA7F060a2BEDeE6b11927CC9c3eF1' +tokens: + - symbol: GLMR + address: '0x0000000000000000000000000000000000000000' + decimals: 18 + type: native + - symbol: ETH + address: '0xfa9343c3897324496a05fc75abed6bac29f8a40f' + decimals: 18 + type: erc20 + - symbol: xcUSDT + name: xcUSDT + address: '0xFFFFFFfFea09FB06d082fd1275CD48b191cbCD1d' + decimals: 6 + type: erc20 + - symbol: xcPINK + name: xcPINK + address: '0xffffffff30478fafbe935e466da114e14fb3563d' + decimals: 10 + type: erc20 +couples: + + # usdt + - chain: darwinia-dvm + symbol: xcUSDT/ahUSDT + protocol: lnv3 + fee: '1000' + messager: msgline + category: usdt + - chain: arbitrum + symbol: USDT + protocol: lnv3 + fee: '10000000' + messager: msgline + + + ## pingk + - chain: darwinia-dvm + symbol: xcPINK/ahPINK + protocol: lnv3 + fee: '1000' + messager: msgline + category: pink + diff --git a/conf/mainnets/optimism.yml b/conf/mainnets/optimism.yml new file mode 100644 index 0000000..01bfc7d --- /dev/null +++ b/conf/mainnets/optimism.yml @@ -0,0 +1,62 @@ +id: "10" +code: op +name: Op +rpcs: + - https://optimism-rpc.publicnode.com +messagers: + - name: layerzero + address: '0x61B6B8c7C00aA7F060a2BEDeE6b11927CC9c3eF1' +tokens: + - symbol: eth + address: '0x0000000000000000000000000000000000000000' + decimals: 18 + type: native + - symbol: usdt + address: '0x94b008aA00579c1307B0EF2c499aD98a8ce58e58' + decimals: 6 + type: erc20 +couples: + + ## eth + - chain: arbitrum + symbol: eth + protocol: lnv3 + fee: '10000000000000' + messager: layerzero + + ## usdt + - chain: bsc + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: polygon + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: linea + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: arbitrum + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: mantle + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: scroll + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: gnosis + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero diff --git a/conf/mainnets/polygon-zkevm.yml b/conf/mainnets/polygon-zkevm.yml new file mode 100644 index 0000000..a3b397e --- /dev/null +++ b/conf/mainnets/polygon-zkevm.yml @@ -0,0 +1,28 @@ +id: "1101" +code: polygon-zkEvm +name: Polygon zkEVM +rpcs: + - https://zkevm-rpc.com +tokens: + - symbol: eth + address: '0x0000000000000000000000000000000000000000' + decimals: 18 + type: native + - symbol: usdt + address: '0x1E4a5963aBFD975d8c9021ce480b42188849D41d' + decimals: 6 + type: erc20 +couples: + + ## usdt + - chain: polygon + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: bsc + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + diff --git a/conf/mainnets/polygon.yml b/conf/mainnets/polygon.yml new file mode 100644 index 0000000..75cc936 --- /dev/null +++ b/conf/mainnets/polygon.yml @@ -0,0 +1,77 @@ +id: "137" +code: polygon +name: Polygon +rpcs: + - https://polygon-bor-rpc.publicnode.com +messagers: + - name: layerzero + address: '0x463D1730a8527CA58d48EF70C7460B9920346567' +tokens: + - symbol: MATIC + address: '0x0000000000000000000000000000000000000000' + decimals: 18 + type: native + - symbol: ring + address: '0x9C1C23E60B72Bc88a043bf64aFdb16A02540Ae8f' + decimals: 18 + type: erc20 + - symbol: usdt + address: '0xc2132D05D31c914a87C6611C10748AEb04B58e8F' + decimals: 6 + type: erc20 +couples: + + ## ring + - chain: arbitrum + symbol: ring + protocol: lnv2-default + fee: '100000000000000000000' + messager: layerzero + - chain: darwinia-dvm + symbol: RING + protocol: lnv3 + fee: '30000000000000000000' + messager: msgline + + ## usdt + - chain: polygon-zkEvm + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: arbitrum + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: linea + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: op + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: bsc + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: mantle + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: scroll + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: gnosis + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + diff --git a/conf/mainnets/scroll.yml b/conf/mainnets/scroll.yml new file mode 100644 index 0000000..bb042f3 --- /dev/null +++ b/conf/mainnets/scroll.yml @@ -0,0 +1,77 @@ +id: "534352" +code: scroll +name: Scroll +rpcs: + - https://scroll-mainnet.public.blastapi.io +messagers: + - name: layerzero + address: '0x463d1730a8527ca58d48ef70c7460b9920346567' +tokens: + - symbol: eth + address: '0x0000000000000000000000000000000000000000' + decimals: 18 + type: native + - symbol: usdt + address: '0xf55BEC9cafDbE8730f096Aa55dad6D22d44099Df' + decimals: 6 + type: erc20 + - symbol: usdc + address: '0x06eFdBFf2a14a7c8E15944D1F4A48F9F95F663A4' + decimals: 6 + type: erc20 +couples: + + ## usdt + - chain: mantle + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: zksync + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: arbitrum + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: bsc + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: polygon + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: linea + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: op + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: gnosis + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + + + ## usdc + - chain: mantle + symbol: usdc + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: arbitrum + symbol: usdc + protocol: lnv2-default + fee: '100000' + messager: layerzero diff --git a/conf/mainnets/taiko.yml b/conf/mainnets/taiko.yml new file mode 100644 index 0000000..7dbd179 --- /dev/null +++ b/conf/mainnets/taiko.yml @@ -0,0 +1,34 @@ +id: "167000" +code: taiko +name: taiko +rpcs: + - https://rpc.taiko.xyz +tokens: + - symbol: eth + address: '0x0000000000000000000000000000000000000000' + decimals: 18 + type: native + - symbol: usdt + address: '0x89AF830781A2C1d3580Db930bea11094F55AfEae' + decimals: 18 + type: erc20 + - symbol: usdc + address: '0x3F7DF5866591e7E48D18C8EbeAE61Bc343a63283' + decimals: 18 + type: erc20 +couples: + + ## usdt + - chain: arbitrum-sepolia + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + + ## usdc + - chain: arbitrum-sepolia + symbol: USDC + protocol: lnv2-default + fee: '100000' + messager: layerzero + diff --git a/conf/mainnets/zksync.yml b/conf/mainnets/zksync.yml new file mode 100644 index 0000000..789b7c3 --- /dev/null +++ b/conf/mainnets/zksync.yml @@ -0,0 +1,40 @@ +id: "324" +code: zksync +name: zksync +rpcs: + - https://mainnet.era.zksync.io +messagers: + - name: layerzero + address: '0x96892F3EaD26515592Da38432cFABad991BBd69d' +tokens: + - symbol: 'eth' + address: '0x0000000000000000000000000000000000000000' + decimals: 18 + type: native + - symbol: usdt + address: '0x493257fD37EDB34451f62EDf8D2a0C418852bA4C' + decimals: 6 + type: erc20 + - symbol: usdc + address: '0x3355df6D4c9C3035724Fd0e3914dE96A5a83aaf4' + decimals: 6 + type: erc20 +couples: + + ## usdt + - chain: arbitrum + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: mantle + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + - chain: scroll + symbol: USDT + protocol: lnv2-default + fee: '100000' + messager: layerzero + diff --git a/conf/testnets/$.yml b/conf/testnets/$.yml new file mode 100644 index 0000000..99a0b10 --- /dev/null +++ b/conf/testnets/$.yml @@ -0,0 +1,8 @@ + +protocol: + lnv2-default: '0x8429D7Dfd91D6F970ba89fFC005e67D15f1E4739' + lnv2-opposite: '0xbA96d83E2A04c4E50F2D6D7eCA03D70bA2426e5f' + lnv3: '0x38627Cb033De66a1E07e73f5D0a7a7adFB6741fa' +messagers: +# - name: msgline +# address: '0x65Be094765731F394bc6d9DF53bDF3376F1Fc8B0' diff --git a/conf/testnets/arbitrum-sepolia.yml b/conf/testnets/arbitrum-sepolia.yml new file mode 100644 index 0000000..eb98a38 --- /dev/null +++ b/conf/testnets/arbitrum-sepolia.yml @@ -0,0 +1,94 @@ +id: "421614" +code: arbitrum-sepolia +name: Arbitrum sepolia +rpcs: + - https://public.stackup.sh/api/v1/node/arbitrum-sepolia +tokens: + - symbol: 'eth' + address: '0x0000000000000000000000000000000000000000' + decimals: 18 + type: native + - symbol: 'usdt' + address: '0x3b8Bb7348D4F581e67E2498574F73e4B9Fc51855' + decimals: 18 + type: erc20 + - symbol: 'usdc' + address: '0x8A87497488073307E1a17e8A12475a94Afcb413f' + decimals: 18 + type: erc20 +couples: + - chain: morph + symbol: usdc + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + category: usdc + - chain: bera + symbol: usdc + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + category: usdc + - chain: taiko-hekla + symbol: usdc + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + category: usdc + - chain: sepolia + symbol: usdc + protocol: lnv2-opposite + fee: '100000000000000000' + category: usdc + messager: layerzero + - chain: zksync-sepolia + symbol: usdc + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + category: usdc + + - chain: morph + symbol: usdt + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + category: usdt + - chain: bera + symbol: usdt + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + category: usdt + - chain: taiko-hekla + symbol: usdt + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + category: usdt + - chain: sepolia + symbol: usdt + protocol: lnv2-opposite + fee: '100000000000000000' + messager: layerzero + category: usdt + - chain: zksync-sepolia + symbol: usdt + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + category: usdt + + - chain: sepolia + symbol: eth + protocol: lnv2-opposite + fee: '100000000000000000' + messager: layerzero + category: eth + - chain: zksync-sepolia + symbol: eth + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + category: eth + diff --git a/conf/testnets/bera.yml b/conf/testnets/bera.yml new file mode 100644 index 0000000..c409d82 --- /dev/null +++ b/conf/testnets/bera.yml @@ -0,0 +1,34 @@ +id: "80085" +code: bera +name: bera +rpcs: + - https://artio.rpc.berachain.com +tokens: + - symbol: 'BERA' + address: '0x0000000000000000000000000000000000000000' + decimals: 18 + type: native + - symbol: 'usdt' + address: '0x463D1730a8527CA58d48EF70C7460B9920346567' + decimals: 18 + type: erc20 + - symbol: 'usdc' + address: '0x89AF830781A2C1d3580Db930bea11094F55AfEae' + decimals: 18 + type: erc20 + +couples: + ## usdt + - chain: arbitrum-sepolia + symbol: usdt + protocol: lnv2-default + fee: '100000' + messager: layerzero + + ## usdc + - chain: arbitrum-sepolia + symbol: usdc + protocol: lnv2-default + fee: '100000' + messager: layerzero + diff --git a/conf/testnets/morph.yml b/conf/testnets/morph.yml new file mode 100644 index 0000000..4eef6ba --- /dev/null +++ b/conf/testnets/morph.yml @@ -0,0 +1,34 @@ +id: "2710" +code: morph +name: morph +rpcs: + - https://rpc-testnet.morphl2.io +tokens: + - symbol: eth + address: '0x0000000000000000000000000000000000000000' + decimals: 18 + type: native + - symbol: usdt + address: '0x463D1730a8527CA58d48EF70C7460B9920346567' + decimals: 18 + type: erc20 + - symbol: usdc + address: '0x89AF830781A2C1d3580Db930bea11094F55AfEae' + decimals: 18 + type: erc20 +couples: + + # usdt + - chain: arbitrum-sepolia + symbol: usdt + protocol: lnv3 + fee: '100000' + messager: layerzero + + + # usdc + - chain: arbitrum-sepolia + symbol: usdc + protocol: lnv3 + fee: '100000' + messager: layerzero diff --git a/conf/testnets/sepolia.yml b/conf/testnets/sepolia.yml new file mode 100644 index 0000000..b194322 --- /dev/null +++ b/conf/testnets/sepolia.yml @@ -0,0 +1,56 @@ +id: "11155111" +code: sepolia +name: Sepolia +rpcs: + - https://ethereum-sepolia-rpc.publicnode.com +tokens: + - symbol: 'eth' + address: '0x0000000000000000000000000000000000000000' + decimals: 18 + type: native + - symbol: 'usdt' + address: '0x876A4f6eCF13EEb101F9E75FCeF58f19Ff383eEB' + decimals: 18 + type: erc20 + - symbol: 'usdc' + address: '0x0ac58Df0cc3542beC4cDa71B16D06C3cCc39f405' + decimals: 18 + type: erc20 +couples: + ## usdc + - chain: arbitrum-sepolia + symbol: usdc + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + - chain: zksync-sepolia + symbol: usdc + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + + + ## usdt + - chain: arbitrum-sepolia + symbol: usdt + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + - chain: zksync-sepolia + symbol: usdt + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + + - chain: arbitrum-sepolia + symbol: eth + protocol: lnv2-opposite + fee: '100000000000000000' + messager: layerzero + - chain: zksync-sepolia + symbol: eth + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + + diff --git a/conf/testnets/taiko-hekla.yml b/conf/testnets/taiko-hekla.yml new file mode 100644 index 0000000..c6fc91b --- /dev/null +++ b/conf/testnets/taiko-hekla.yml @@ -0,0 +1,32 @@ +id: "167009" +code: taiko-hekla +name: taiko-hekla +rpcs: + - https://rpc.hekla.taiko.xyz +tokens: + - symbol: eth + address: '0x0000000000000000000000000000000000000000' + decimals: 18 + type: native + - symbol: usdt + address: '0x463D1730a8527CA58d48EF70C7460B9920346567' + decimals: 18 + type: erc20 + - symbol: usdc + address: '0x89AF830781A2C1d3580Db930bea11094F55AfEae' + decimals: 18 + type: erc20 +couples: + ## usdt + - chain: arbitrum-sepolia + symbol: usdt + protocol: lnv3 + fee: '100000000000000000' + messager: layerzero + + ## usdc + - chain: arbitrum-sepolia + symbol: usdc + protocol: lnv3 + fee: '100000000000000000' + messager: layerzero diff --git a/conf/testnets/zksync-sepolia.yml b/conf/testnets/zksync-sepolia.yml new file mode 100644 index 0000000..74a8313 --- /dev/null +++ b/conf/testnets/zksync-sepolia.yml @@ -0,0 +1,56 @@ +id: "300" +code: zksync-sepolia +name: zksync-sepolia +rpcs: + - https://zksync-sepolia.drpc.org +tokens: + - symbol: 'eth' + address: '0x0000000000000000000000000000000000000000' + decimals: 18 + type: native + - symbol: 'usdt' + address: '0x3350f1ef046e21E052dCbA60Fc575919CCaFEdeb' + decimals: 6 + type: erc20 + - symbol: 'usdc' + address: '0x253adBFE99Fcd096B9b5502753F96CF78D42eaD0' + decimals: 6 + type: erc20 +couples: + + + ## usdc + - chain: sepolia + symbol: usdc + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + - chain: arbitrum-sepolia + symbol: usdc + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + + ## usdt + - chain: sepolia + symbol: usdt + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + - chain: arbitrum-sepolia + symbol: usdt + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + + ## eth + - chain: sepolia + symbol: eth + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero + - chain: arbitrum-sepolia + symbol: eth + protocol: lnv2-default + fee: '100000000000000000' + messager: layerzero diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..a8bebe2 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,97 @@ +{ + "name": "helixconf-generate", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "helixconf-generate", + "version": "1.0.0", + "license": "ISC", + "devDependencies": { + "@jvitela/mustache-wax": "^1.0.4", + "change-case": "^5.4.4", + "mustache": "^4.2.0", + "zx": "^8.1.3" + } + }, + "node_modules/@jvitela/mustache-wax": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@jvitela/mustache-wax/-/mustache-wax-1.0.4.tgz", + "integrity": "sha512-cGugVYp0WO7w89KQlyyt2rQyCO5MbrKeqtIAkG8oBfOaiHoeGeKG7WYdBFHftvoZUuK4WFbWyn3hgFipdetC+Q==", + "dev": true, + "peerDependencies": { + "mustache": "^4.2.0" + } + }, + "node_modules/@types/fs-extra": { + "version": "11.0.4", + "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-11.0.4.tgz", + "integrity": "sha512-yTbItCNreRooED33qjunPthRcSjERP1r4MqCZc7wv0u2sUkzTFp45tgUfS5+r7FrZPdmCCNflLhVSP/o+SemsQ==", + "dev": true, + "optional": true, + "dependencies": { + "@types/jsonfile": "*", + "@types/node": "*" + } + }, + "node_modules/@types/jsonfile": { + "version": "6.1.4", + "resolved": "https://registry.npmjs.org/@types/jsonfile/-/jsonfile-6.1.4.tgz", + "integrity": "sha512-D5qGUYwjvnNNextdU59/+fI+spnwtTFmyQP0h+PfIOSkNfpU6AOICUOkm4i0OnSk+NyjdPJrxCDro0sJsWlRpQ==", + "dev": true, + "optional": true, + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/node": { + "version": "20.14.9", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.9.tgz", + "integrity": "sha512-06OCtnTXtWOZBJlRApleWndH4JsRVs1pDCc8dLSQp+7PpUpX3ePdHyeNSFTeSe7FtKyQkrlPvHwJOW3SLd8Oyg==", + "dev": true, + "optional": true, + "dependencies": { + "undici-types": "~5.26.4" + } + }, + "node_modules/change-case": { + "version": "5.4.4", + "resolved": "https://registry.npmjs.org/change-case/-/change-case-5.4.4.tgz", + "integrity": "sha512-HRQyTk2/YPEkt9TnUPbOpr64Uw3KOicFWPVBb+xiHvd6eBx/qPr9xqfBFDT8P2vWsvvz4jbEkfDe71W3VyNu2w==", + "dev": true + }, + "node_modules/mustache": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz", + "integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==", + "dev": true, + "bin": { + "mustache": "bin/mustache" + } + }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true, + "optional": true + }, + "node_modules/zx": { + "version": "8.1.3", + "resolved": "https://registry.npmjs.org/zx/-/zx-8.1.3.tgz", + "integrity": "sha512-fA44CRlggDOKeqt66aMwzLj1tb0zEQJmIjsSDXpmNjRRKaLFYkpeGE/zXnO05sJvSuzAlbVM50zexJJGMrIvuQ==", + "dev": true, + "bin": { + "zx": "build/cli.js" + }, + "engines": { + "node": ">= 12.17.0" + }, + "optionalDependencies": { + "@types/fs-extra": ">=11", + "@types/node": ">=20" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..dbf6636 --- /dev/null +++ b/package.json @@ -0,0 +1,18 @@ +{ + "name": "helixconf-generate", + "version": "1.0.0", + "description": "Generate Helix conf", + "scripts": { + "generate": "zx scripts/generate/index.mjs", + "build:ts": "npm run generate -- --language=ts && cd generated/typescript && npm i && npm run build", + "test:ts": "npm run build:ts && cd generated/typescript && npm run test" + }, + "author": "", + "license": "ISC", + "devDependencies": { + "@jvitela/mustache-wax": "^1.0.4", + "change-case": "^5.4.4", + "mustache": "^4.2.0", + "zx": "^8.1.3" + } +} diff --git a/scripts/generate/_helper.mjs b/scripts/generate/_helper.mjs new file mode 100644 index 0000000..f8fe478 --- /dev/null +++ b/scripts/generate/_helper.mjs @@ -0,0 +1,48 @@ +export function mergeObjects(obj1, obj2) { + for (let key in obj1) { + if (!obj1.hasOwnProperty(key)) { + continue; + } + + if (Array.isArray(obj1[key])) { + if (!Array.isArray(obj2[key])) { + obj2[key] = []; + } + obj2[key] = mergeArrays(obj1[key], obj2[key]); + } else if (typeof obj1[key] === 'object' && obj1[key] !== null) { + if (typeof obj2[key] !== 'object' || obj2[key] === null) { + obj2[key] = {}; + } + mergeObjects(obj1[key], obj2[key]); + } else if (!(key in obj2)) { + obj2[key] = obj1[key]; + } + } + return obj2; +} + +export function mergeArrays(arr1, arr2) { + arr1.forEach(item1 => { + if (Array.isArray(item1)) { + arr2.push(mergeArrays(item1, [])); + } else if (typeof item1 === 'object' && item1 !== null) { + // let found = false; + // for (let i = 0; i < arr2.length; i++) { + // if (typeof arr2[i] === 'object' && arr2[i] !== null && !Array.isArray(arr2[i])) { + // if (Object.keys(item1).every(key => arr2[i].hasOwnProperty(key))) { + // console.log('found' , item1) + // mergeObjects(item1, arr2[i]); + // found = true; + // break; + // } + // } + // } + // if (!found) { + arr2.push(mergeObjects(item1, {})); + // } + } else if (!arr2.includes(item1)) { + arr2.push(item1); + } + }); + return arr2; +} diff --git a/scripts/generate/index.mjs b/scripts/generate/index.mjs new file mode 100644 index 0000000..3714530 --- /dev/null +++ b/scripts/generate/index.mjs @@ -0,0 +1,70 @@ +import * as helper from './_helper.mjs' +import * as stdconf from './stdconf.mjs' +import * as renderer from './renderer/index.mjs' + + +const BIN_PATH = path.resolve(__filename, '../'); +const WORK_PATH = path.resolve(BIN_PATH, '../../'); + +async function readConf(lifecycle) { + const chainMap = {}; + for (const network of lifecycle.networks) { + const pathNetwork = `${WORK_PATH}/conf/${network}`; + const rawDefinition = await fs.readFile(`${pathNetwork}/$.yml`, 'utf8'); + const global = YAML.parse(rawDefinition); + + const filesOfNetwork = await fs.readdir(pathNetwork); + for (const fileName of filesOfNetwork) { + if (fileName === '$.yml') continue; + const rawNetwork = await fs.readFile(`${pathNetwork}/${fileName}`, 'utf8'); + const networkConf = YAML.parse(rawNetwork); + chainMap[networkConf.code] = { + ...networkConf, + _network: network, + _global: global, + }; + } + } + return chainMap; +} + +function reorganizationConf(conf) { + const names = Object.keys(conf); + const newChainConf = {}; + for (const name of names) { + const ccf = conf[name]; + const nccf = helper.mergeObjects(ccf._global, ccf); + stdconf.standardization(conf, nccf); + + newChainConf[name] = nccf; + } + return newChainConf; +} + + +async function generateLangauge(lifecycle) { + const language = (argv['language'] || 'js').toUpperCase(); + await renderer.render(lifecycle, language); +} + +async function main() { + const _networkArg = argv['network']; + const networks = _networkArg + ? (typeof _networkArg) === 'string' ? [_networkArg] : _networkArg + : ['mainnets', 'testnets']; + const lifecycle = { + workdir: WORK_PATH, + networks, + }; + const baseConf = await readConf(lifecycle); + lifecycle.conf = reorganizationConf(baseConf); + await fs.writeFile(`${WORK_PATH}/_tmp/output.json`, JSON.stringify(lifecycle.conf, null, 2)); + + await generateLangauge(lifecycle); +} + +await main(); + + + + diff --git a/scripts/generate/renderer/index.mjs b/scripts/generate/renderer/index.mjs new file mode 100644 index 0000000..d9b2db2 --- /dev/null +++ b/scripts/generate/renderer/index.mjs @@ -0,0 +1,37 @@ +import * as langTs from './lang_ts.mjs' + +import * as changeCase from "change-case"; + +const Mustache = require('mustache'); +const Wax = require('@jvitela/mustache-wax'); + +Wax(Mustache); +Mustache.Formatters = { + json_stringify: object => JSON.stringify(object, null, 2), + camel_case: text => changeCase.camelCase(text), // twoWords + capital_case: text => changeCase.capitalCase(text), // Two Words + constant_case: text => changeCase.constantCase(text), // TWO_WORDS + dot_case: text => changeCase.dotCase(text), // two.words + kebab_case: text => changeCase.kebabCase(text), // two-words + no_case: text => changeCase.noCase(text), // two words + pascal_case: text => changeCase.pascalCase(text), // TwoWords + pascal_snake_case: text => changeCase.pascalSnakeCase(text), // Two_Words + path_case: text => changeCase.pathCase(text), // two/words + sentence_case: text => changeCase.sentenceCase(text), // Two words + snake_case: text => changeCase.snakeCase(text), // two_words + train_case: text => changeCase.trainCase(text), // Two-Words + upper_case: text => text ? text.toUpperCase() : text, // TWO WORDS + lower_case: text => text ? text.toLowerCase() : text, // two words +}; + + +export async function render(lifecycle, language) { + switch (language) { + case 'JS': + case 'TS': + case 'JAVASCRIPT': + case 'TYPESCRIPT': { + await langTs.render(lifecycle); + } + } +} diff --git a/scripts/generate/renderer/lang_ts.mjs b/scripts/generate/renderer/lang_ts.mjs new file mode 100644 index 0000000..adf5b4a --- /dev/null +++ b/scripts/generate/renderer/lang_ts.mjs @@ -0,0 +1,42 @@ +const Mustache = require('mustache'); + +export async function render(lifecycle) { + const {workdir, conf} = lifecycle + const langTs = { + templateDir: `${workdir}/template/ts/templates`, + filesDir: `${workdir}/template/ts/files`, + baseDir: `${workdir}/generated/typescript`, + srcDir: `${workdir}/generated/typescript/src`, + }; + lifecycle.langTs = langTs; + + await fs.mkdirp(langTs.srcDir); + await copyFiles(lifecycle) + await renderChain(lifecycle); +} + +async function renderChain(lifecycle) { + const {conf, langTs} = lifecycle; + const chainNames = Object.keys(conf); + const chainTpl = await fs.readFile(`${langTs.templateDir}/chain.ts.mustache`, 'utf8'); + + const chainList = []; + for (const name of chainNames) { + const cf = conf[name]; + const networkDir = `${langTs.srcDir}/${cf._network}`; + await fs.mkdirp(networkDir); + const output = Mustache.render(chainTpl, {chain: cf}); + await fs.writeFile(`${networkDir}/${name}.ts`, output); + chainList.push({network: cf._network, name: name}); + } + chainList[chainList.length - 1].last = true + + const indexTpl = await fs.readFile(`${langTs.templateDir}/index.ts.mustache`, 'utf8'); + const output = Mustache.render(indexTpl, {chains: chainList}); + await fs.writeFile(`${langTs.srcDir}/index.ts`, output); +} + +async function copyFiles(lifecycle) { + const {conf, langTs} = lifecycle; + await fs.copy(langTs.filesDir, langTs.baseDir, {overwrite: true}); +} diff --git a/scripts/generate/stdconf.mjs b/scripts/generate/stdconf.mjs new file mode 100644 index 0000000..eec4fca --- /dev/null +++ b/scripts/generate/stdconf.mjs @@ -0,0 +1,106 @@ +export function standardization(global, ccf) { + _stdTokens(global, ccf); + _stdCouples(global, ccf); + _cleanConf(global, ccf); +} + +function _stdCouples(global, ccf) { + if (!ccf.couples) return; + for (const couple of ccf.couples) { + _stdSymbol(global, ccf, couple); + _stdMessager(global, ccf, couple); + _stdProtocol(global, ccf, couple); + _stdChain(global, ccf, couple); + _stdCategory(global, ccf, couple); + } +} + + +function _stdTokens(global, ccf) { + for (const token of ccf.tokens) { + token.symbol = token.symbol.toUpperCase(); + if (!token.name) { + token.name = token.symbol; + } + } +} + +function _stdSymbol(global, ccf, couple) { + const rawSymbol = couple.symbol; + if (typeof rawSymbol === 'string') { + const pairs = rawSymbol.split('/'); + if (pairs.length === 1) { + couple.symbol = { + from: pairs[0].toUpperCase(), + to: pairs[0].toUpperCase(), + }; + return; + } + couple.symbol = { + from: pairs[0].toUpperCase(), + to: pairs[1].toUpperCase(), + }; + return; + } + if (rawSymbol.from && rawSymbol.to) { + rawSymbol.from = rawSymbol.from.toUpperCase(); + rawSymbol.to = rawSymbol.to.toUpperCase(); + return; + } + console.log(chalk.red('missing symbol; symbol: {from, to}')); + process.exit(1); +} + +function _stdMessager(global, ccf, couple) { + if (!ccf.messagers) ccf.messagers = []; + if (!couple.messager) return; + couple.messager = __pickMessager(ccf, couple.messager); +} + +function _stdProtocol(global, ccf, couple) { + if (!ccf.protocol) { + couple.protocol = { + name: couple.protocol, + }; + return; + } + const protocolAddress = ccf.protocol[couple.protocol]; + couple.protocol = { + name: couple.protocol, + address: protocolAddress, + }; +} + +function _stdCategory(global, ccf, couple) { + if (couple.category) { + couple.category = couple.category.toUpperCase(); + return; + } + couple.category = couple.symbol.from; +} + +function _stdChain(global, ccf, couple) { + const chainCode = couple.chain; + const targetChain = global[chainCode]; + if (!targetChain) { + console.log(chalk.red(`missing couple chain [${chainCode}] from [${ccf.code}], maybe you typed wrong chain code`)); + process.exit(1); + } + couple.chain = { + id: targetChain.id, + code: chainCode, + name: targetChain.name, + }; +} + +function _cleanConf(global, ccf) { + delete ccf['_global']; +} + +function __pickMessager(ccf, name) { + if (!ccf.messagers) return {name}; + for (const messager of ccf.messagers) { + if (messager.name === name) return messager; + } + return {name}; +} diff --git a/template/ts/files/.editorconfig b/template/ts/files/.editorconfig new file mode 100644 index 0000000..99580d0 --- /dev/null +++ b/template/ts/files/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true diff --git a/template/ts/files/.gitignore b/template/ts/files/.gitignore new file mode 100644 index 0000000..9f65662 --- /dev/null +++ b/template/ts/files/.gitignore @@ -0,0 +1,10 @@ +*.retry +.DS_Store +*.local.* + +node_modules + +/generated +dist +_tmp + diff --git a/template/ts/files/jest.config.js b/template/ts/files/jest.config.js new file mode 100644 index 0000000..3745fc2 --- /dev/null +++ b/template/ts/files/jest.config.js @@ -0,0 +1,5 @@ +/** @type {import('ts-jest').JestConfigWithTsJest} */ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', +}; diff --git a/template/ts/files/package.json b/template/ts/files/package.json new file mode 100644 index 0000000..1d50475 --- /dev/null +++ b/template/ts/files/package.json @@ -0,0 +1,19 @@ +{ + "name": "helixconf", + "version": "0.0.1", + "description": "Helix conf", + "main": "dist/index.js", + "scripts": { + "build": "rm -rf dist && tsc", + "test": "jest" + }, + "author": "HelixBridge", + "license": "MIT", + "devDependencies": { + "@types/jest": "^29.5.12", + "jest": "^29.7.0", + "ts-jest": "^29.1.5", + "ts-node": "^10.9.2", + "typescript": "^5.5.3" + } +} diff --git a/template/ts/files/src/helixconf.ts b/template/ts/files/src/helixconf.ts new file mode 100644 index 0000000..4ea12f7 --- /dev/null +++ b/template/ts/files/src/helixconf.ts @@ -0,0 +1,135 @@ +export type HelixProtocolName = 'lnv2-default' | 'lnv2-opposite' | 'lnv3'; +export type TokenType = 'native' | 'erc20'; +export type _NetworkType = 'mainnets' | 'testnets'; + + +export interface ChainMessager { + name: string + address?: string +} + +export interface ChainToken { + symbol: string + address: string + decimals: number + type: TokenType, + name: string +} + +export interface ChainCouple { + category: string + messager: ChainMessager + fee: string + protocol: HelixProtocol + symbol: CoupleSymbol + chain: CoupleChain +} + +export interface CoupleChain { + id: BigInt + code: string + name: string +} + +export interface CoupleSymbol { + from: string + to: string +} + +export interface HelixProtocol { + name: HelixProtocolName, + address: string +} + +export interface CoupleFilter { + category?: string + messager?: string + protocol?: string + chain?: string + symbolFrom?: string + symbolTo?: string + symbol?: string +} + +export class HelixChainConf { + + constructor( + public readonly _network: _NetworkType, + public readonly id: BigInt, + public readonly code: string, + public readonly name: string, + public readonly rpcs: string[], + public readonly protocol: Partial>, + public readonly messagers: ChainMessager[], + public readonly tokens: ChainToken[], + public readonly couples: ChainCouple[], + ) { + } + + static fromJson(json: any): HelixChainConf { + return new HelixChainConf( + json._network, + BigInt(json.id), + json.code, + json.name, + json.rpcs, + json.protocol, + json.messagers, + json.tokens, + json.couples, + ); + } + + categories(): string[] { + return this.couples.map(item => item.category); + } + + filterCouple(filter: CoupleFilter): ChainCouple[] { + if (!filter) return this.couples; + return this.couples.filter(item => { + if (filter.category) { + if (!_equalsIgnoreCase(item.category, filter.category)) { + return false; + } + } + if (filter.messager) { + const eq = _equalsIgnoreCase(item.messager.name, filter.messager) + || _equalsIgnoreCase(item.messager.address, filter.messager); + if (!eq) return false; + } + if (filter.protocol) { + const eq = _equalsIgnoreCase(item.protocol.name, filter.messager) + || _equalsIgnoreCase(item.protocol.address, filter.messager); + if (!eq) return false; + } + if (filter.chain) { + const eq = _equalsIgnoreCase(item.chain.id.toString(), filter.chain) + || _equalsIgnoreCase(item.chain.code, filter.chain) + || _equalsIgnoreCase(item.chain.name, filter.chain); + if (!eq) return false; + } + if (filter.symbolFrom) { + if (!_equalsIgnoreCase(item.symbol.from, filter.symbolFrom)) return false; + } + if (filter.symbolTo) { + if (!_equalsIgnoreCase(item.symbol.to, filter.symbolTo)) return false; + } + if (filter.symbol) { + const eq = _equalsIgnoreCase(item.symbol.from, filter.symbol) + || _equalsIgnoreCase(item.symbol.to, filter.symbol); + if (!eq) return false; + } + return true; + }); + } + +} + + +function _equalsIgnoreCase(t1?: string, t2?: string) { + if (!t1 || !t2) { + return false; + } + return t1.toLowerCase() === t2.toLowerCase(); +} + diff --git a/template/ts/files/tests/helixconf.test.ts b/template/ts/files/tests/helixconf.test.ts new file mode 100644 index 0000000..1d785c7 --- /dev/null +++ b/template/ts/files/tests/helixconf.test.ts @@ -0,0 +1,10 @@ +import {HelixChain} from '../src/' + +describe('helixconf_test', () => { + test('test_chainId', () => { + expect(42161n).toStrictEqual(HelixChain.arbitrum.id); + expect(46n).toStrictEqual(HelixChain.darwiniaDvm.id); + expect(44n).toStrictEqual(HelixChain.crabDvm.id); + }); +}); + diff --git a/template/ts/files/tsconfig.json b/template/ts/files/tsconfig.json new file mode 100644 index 0000000..3abc7b9 --- /dev/null +++ b/template/ts/files/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "target": "ESNext", + "module": "CommonJS", + "rootDir": "./", + "moduleResolution": "node", + "declaration": true, + "outDir": "./dist", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true + }, + "exclude": [ + "node_modules", + "dist" + ] +} diff --git a/template/ts/templates/chain.ts.mustache b/template/ts/templates/chain.ts.mustache new file mode 100644 index 0000000..1217768 --- /dev/null +++ b/template/ts/templates/chain.ts.mustache @@ -0,0 +1,3 @@ +import {HelixChainConf} from '../helixconf' + +export const {{ chain.code | camel_case }}Chain: HelixChainConf = HelixChainConf.fromJson({{ &chain | json_stringify }}); diff --git a/template/ts/templates/index.ts.mustache b/template/ts/templates/index.ts.mustache new file mode 100644 index 0000000..cc0bbbb --- /dev/null +++ b/template/ts/templates/index.ts.mustache @@ -0,0 +1,21 @@ +{{#chains}} +import { {{ name | camel_case }}Chain } from './{{ network }}/{{ name }}' +{{/chains}} +import { HelixChainConf } from './helixconf' + + +export class HelixChain { +{{#chains}} + static {{ name | camel_case }}: HelixChainConf = {{ name | camel_case }}Chain; +{{/chains}} + static get(name: string): HelixChainConf | undefined { + switch(name.toUpperCase()) { + {{#chains}} + case '{{ name | upper_case }}': + return {{ name | camel_case }}Chain; + {{/chains}} + } + } +} + +