mirror of
https://github.com/vacp2p/linea-monorepo.git
synced 2026-01-08 19:58:01 -05:00
Co-authored-by: Franklin Delehelle <franklin.delehelle@odena.eu> Co-authored-by: Alexandre Belling <alexandrebelling8@gmail.com> Co-authored-by: Pedro Novais <jpvnovais@gmail.com> Co-authored-by: Roman Vaseev <4833306+Filter94@users.noreply.github.com> Co-authored-by: Bradley Bown <bradbown@googlemail.com> Co-authored-by: Victorien Gauch <85494462+VGau@users.noreply.github.com> Co-authored-by: Nikolai Golub <nikolai.golub@consensys.net> Co-authored-by: The Dark Jester <thedarkjester@users.noreply.github.com> Co-authored-by: jonesho <81145364+jonesho@users.noreply.github.com> Co-authored-by: Gaurav Ahuja <gauravahuja9@gmail.com> Co-authored-by: Azam Soleimanian <49027816+Soleimani193@users.noreply.github.com> Co-authored-by: Andrei A <andrei.alexandru@consensys.net> Co-authored-by: Arijit Dutta <37040536+arijitdutta67@users.noreply.github.com> Co-authored-by: Gautam Botrel <gautam.botrel@gmail.com> Co-authored-by: Ivo Kubjas <ivo.kubjas@consensys.net> Co-authored-by: gusiri <dreamerty@postech.ac.kr> Co-authored-by: FlorianHuc <florian.huc@gmail.com> Co-authored-by: Arya Tabaie <arya.pourtabatabaie@gmail.com> Co-authored-by: Julink <julien.fontanel@consensys.net> Co-authored-by: Bogdan Ursu <bogdanursuoffice@gmail.com> Co-authored-by: Jakub Trąd <jakubtrad@gmail.com> Co-authored-by: Alessandro Sforzin <alessandro.sforzin@consensys.net> Co-authored-by: Olivier Bégassat <olivier.begassat.cours@gmail.com> Co-authored-by: Steve Huang <97596526+stevehuangc7s@users.noreply.github.com> Co-authored-by: bkolad <blazejkolad@gmail.com> Co-authored-by: fadyabuhatoum1 <139905934+fadyabuhatoum1@users.noreply.github.com> Co-authored-by: Blas Rodriguez Irizar <rodrigblas@gmail.com> Co-authored-by: Eduardo Andrade <eduardofandrade@gmail.com> Co-authored-by: Ivo Kubjas <tsimmm@gmail.com> Co-authored-by: Ludcour <ludovic.courcelas@consensys.net> Co-authored-by: m4sterbunny <harrie.bickle@consensys.net> Co-authored-by: Alex Panayi <145478258+alexandrospanayi@users.noreply.github.com> Co-authored-by: Diana Borbe - ConsenSys <diana.borbe@consensys.net> Co-authored-by: ThomasPiellard <thomas.piellard@gmail.com>
162 lines
4.5 KiB
TypeScript
162 lines
4.5 KiB
TypeScript
export const name = 'Linea';
|
|
export const version = '0.0.1';
|
|
export const license = 'MIT';
|
|
|
|
const WETH_ADDR = '0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f';
|
|
const USDC_ADDR = '0x176211869cA2b568f2A7D4EE941E073a821EE1ff';
|
|
const FROM_ADDR = '0x8C8766c1Ac7308604C80387f1bF8128386b64de9';
|
|
const TO_ADDR = '0xB1c25ff9F709cA3cd88D398586dd02aC62fce5BB'
|
|
|
|
const PANCAKE_SWAP_ROUTER = '0x1b81D678ffb9C0263b24A97847620C99d213eB14';
|
|
type TxType = 'EthTransfer' | 'ERC20Transfer' | 'ERC20Swap';
|
|
const PANCAKE_SWAP_EXACT_INPUT_SINGLE_ABI = [
|
|
{
|
|
"inputs": [
|
|
{
|
|
"components": [
|
|
{
|
|
"internalType": "address",
|
|
"name": "tokenIn",
|
|
"type": "address"
|
|
},
|
|
{
|
|
"internalType": "address",
|
|
"name": "tokenOut",
|
|
"type": "address"
|
|
},
|
|
{
|
|
"internalType": "uint24",
|
|
"name": "fee",
|
|
"type": "uint24"
|
|
},
|
|
{
|
|
"internalType": "address",
|
|
"name": "recipient",
|
|
"type": "address"
|
|
},
|
|
{
|
|
"internalType": "uint256",
|
|
"name": "deadline",
|
|
"type": "uint256"
|
|
},
|
|
{
|
|
"internalType": "uint256",
|
|
"name": "amountIn",
|
|
"type": "uint256"
|
|
},
|
|
{
|
|
"internalType": "uint256",
|
|
"name": "amountOutMinimum",
|
|
"type": "uint256"
|
|
},
|
|
{
|
|
"internalType": "uint160",
|
|
"name": "sqrtPriceLimitX96",
|
|
"type": "uint160"
|
|
}
|
|
],
|
|
"internalType": "struct ISwapRouter.ExactInputSingleParams",
|
|
"name": "params",
|
|
"type": "tuple"
|
|
}
|
|
],
|
|
"name": "exactInputSingle",
|
|
"outputs": [
|
|
{
|
|
"internalType": "uint256",
|
|
"name": "amountOut",
|
|
"type": "uint256"
|
|
}
|
|
],
|
|
"stateMutability": "payable",
|
|
"type": "function"
|
|
}
|
|
]
|
|
|
|
const USDC_CONTRACT_TRANSFER_ABI = [
|
|
{
|
|
"inputs": [
|
|
{
|
|
"internalType": "address",
|
|
"name": "to",
|
|
"type": "address"
|
|
},
|
|
{
|
|
"internalType": "uint256",
|
|
"name": "value",
|
|
"type": "uint256"
|
|
}
|
|
],
|
|
"name": "transfer",
|
|
"outputs": [
|
|
{
|
|
"internalType": "bool",
|
|
"name": "",
|
|
"type": "bool"
|
|
}
|
|
],
|
|
"stateMutability": "nonpayable",
|
|
"type": "function"
|
|
}
|
|
]
|
|
|
|
export function setup(sdk: Context) {
|
|
sdk.ethers.addProvider('linea', 'https://rpc.linea.build');
|
|
|
|
const getFeeForCost = async (gasAmt: number) => {
|
|
const weiPerGas = await sdk.ethers.getProvider('linea').getGasPrice();
|
|
const ethPrice = await sdk.defiLlama.getCurrentPrice('coingecko', 'ethereum');
|
|
|
|
return (weiPerGas * gasAmt * ethPrice) / 1e18;
|
|
};
|
|
|
|
const getGasAmount = async (txType: TxType): Promise<number> => {
|
|
const provider = sdk.ethers.getProvider('linea');
|
|
const pancakeSwapContract = sdk.ethers.getContract(PANCAKE_SWAP_ROUTER, PANCAKE_SWAP_EXACT_INPUT_SINGLE_ABI, 'linea');
|
|
const usdcContract = sdk.ethers.getContract(USDC_ADDR, USDC_CONTRACT_TRANSFER_ABI, 'linea');
|
|
|
|
if (txType === 'EthTransfer') {
|
|
return provider.estimateGas({
|
|
from: FROM_ADDR,
|
|
to: TO_ADDR,
|
|
value: '0x1',
|
|
data: '0x'
|
|
});
|
|
} else if (txType === 'ERC20Transfer') {
|
|
return usdcContract.estimateGas.transfer(USDC_ADDR, 1, { from: FROM_ADDR });
|
|
} else if (txType === 'ERC20Swap') {
|
|
const params = {
|
|
tokenIn: USDC_ADDR,
|
|
tokenOut: WETH_ADDR,
|
|
fee: '500',
|
|
recipient: FROM_ADDR,
|
|
deadline: 4102401129,
|
|
amountIn: 9447000,
|
|
amountOutMinimum: 0,
|
|
sqrtPriceLimitX96: 0,
|
|
}
|
|
// swap 1 USDC to ETH using KyberSwap with transaction deadline of Dec 31, 2099
|
|
return pancakeSwapContract.estimateGas.exactInputSingle(params, {
|
|
from: FROM_ADDR,
|
|
});
|
|
}
|
|
};
|
|
|
|
sdk.register({
|
|
id: 'linea',
|
|
queries: {
|
|
feeTransferEth: async () => getFeeForCost(await getGasAmount('EthTransfer')),
|
|
feeTransferERC20: async () => getFeeForCost(await getGasAmount('ERC20Transfer')),
|
|
feeSwap: async () => getFeeForCost(await getGasAmount('ERC20Swap')),
|
|
},
|
|
metadata: {
|
|
icon: sdk.ipfs.getDataURILoader('QmXNhh135wo6jUuHdkhUTTV4p63sMpichCERuiyUDPe5vG', 'image/svg+xml'),
|
|
category: 'l2',
|
|
name: 'Linea',
|
|
description: 'Linea zkEVM is the leading ZK scaling solution that is equivalent to Ethereum Virtual Machine.',
|
|
l2BeatSlug: 'linea',
|
|
website: 'https://linea.build',
|
|
},
|
|
});
|
|
}
|