Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add scrips to create proposal for mapping AGG token #2

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 12 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "hardhat-deploy";
import "@nomiclabs/hardhat-ethers";
import {
HardhatUserConfig,
NetworkUserConfig,
Expand All @@ -7,7 +8,7 @@ import * as dotenv from "dotenv";

dotenv.config();

const { TESTNET_URL, MAINNET_URL } = process.env;
const { TESTNET_URL, MAINNET_URL, ETHEREUM_URL } = process.env;

const testnet: NetworkUserConfig = {
chainId: 2021,
Expand All @@ -19,15 +20,25 @@ const mainnet: NetworkUserConfig = {
url: MAINNET_URL || "https://api.roninchain.com/rpc",
};

const ethereum: NetworkUserConfig = {
chainId: 1,
url: ETHEREUM_URL || 'https://gateway.tenderly.co/public/mainnet',
};

const config: HardhatUserConfig = {
paths: {
cache: "hardhat-cache",
sources: "./src",
},

namedAccounts: {
deployer: 0,
governor: 0,
},
networks: {
"ronin-testnet": testnet,
"ronin-mainnet": mainnet,
"ethereum": ethereum,
},
};

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"husky": "^8.0.3",
"lint-staged": "^14.0.1",
"ts-node": "^10.4.0",
"typescript": "^4.5.4"
"typescript": "^4.5.4",
"@nomiclabs/hardhat-ethers": "^2.0.3"
}
}
87 changes: 87 additions & 0 deletions src/scripts/map-token/20231215-maptoken-mainchain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/// npx hardhat deploy --tags MapTokenMainchain --network ethereum

import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { explorerUrl, ProposalSegmentArguments, proxyCall, defaultSegment, checkProposalGas } from '../upgradeUtils';
import { network } from 'hardhat';
import { MainchainGatewayV3__factory } from '../../types';

const deploy = async ({ getNamedAccounts, deployments, ethers }: HardhatRuntimeEnvironment) => {
const { execute } = deployments;
let { governor } = await getNamedAccounts(); // NOTE: Should double check the `governor` account in the `hardhat.config.ts` file
console.log('Governor:', governor);

// const MainchainGatewayProxy = '0x64192819Ac13Ef72bF6b5AE239AC672B43a9AF08';
const MainchainGatewayProxy = await deployments.get('MainchainGatewayV3Proxy');
const MainchainBridgeManager = await deployments.get('MainchainBridgeManager');

const AGGRoninToken = '0x294311a8c37f0744f99eb152c419d4d3d6fec1c7';
const AGGMainchainToken = '0xfb0489e9753b045ddb35e39c6b0cc02ec6b99ac5';

let proposalSegments: ProposalSegmentArguments[] = [
{
...defaultSegment,
target: MainchainGatewayProxy.address,

// function mapTokensAndThresholds(
// address[] calldata _mainchainTokens,
// address[] calldata _roninTokens,
// Token.Standard[] calldata _standards,
// // _thresholds[0]: highTierThreshold
// // _thresholds[1]: lockedThreshold
// // _thresholds[2]: unlockFeePercentages
// // _thresholds[3]: dailyWithdrawalLimit
// uint256[][4] calldata _thresholds
// )

data: proxyCall(MainchainGatewayV3__factory.createInterface().encodeFunctionData('mapTokensAndThresholds', [
[AGGMainchainToken],
[AGGRoninToken],
[0], // Token.Standard ERC20
[
[], // highTierThreshold
[], // lockedThreshold
[], // unlockFeePercentages
[], // dailyWithdrawalLimit
Comment on lines +41 to +44
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBD

],
])),
}
];

if (await checkProposalGas(MainchainBridgeManager.address, ethers.provider, proposalSegments[0])) {
console.log('Not enough gas in the proposal');
return;
}

const blockNumBefore = await ethers.provider.getBlockNumber();
const blockBefore = await ethers.provider.getBlock(blockNumBefore);
const timestampBefore = blockBefore.timestamp;
const proposalExpiryTimestamp = timestampBefore + 3600 * 24 * 10; // expired in 10 days

const tx = await execute(
'MainchainBridgeManager',
{ from: governor, log: true },
'propose',

// function propose(
// uint256 _chainId,
// uint256 _expiryTimestamp,
// address[] calldata _targets,
// uint256[] calldata _values,
// bytes[] calldata _calldatas,
// uint256[] calldata _gasAmounts
// )

1,
proposalExpiryTimestamp, // expiryTimestamp
[...proposalSegments.map((_) => _.target)], // targets
[...proposalSegments.map((_) => _.value)], // values
[...proposalSegments.map((_) => _.data)], // datas
[...proposalSegments.map((_) => _.gasAmount)], // gasAmount
);

console.log(`${explorerUrl[network.name!]}/tx/${tx.transactionHash}`);
};

deploy.tags = ['MapTokenMainchain'];

export default deploy;
78 changes: 78 additions & 0 deletions src/scripts/map-token/20231215-maptoken-roninchain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/// npx hardhat deploy --tags MapTokenRoninchain --network ronin-mainnet

import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { explorerUrl, ProposalSegmentArguments, proxyCall, defaultSegment, checkProposalGas } from '../upgradeUtils';
import { network } from 'hardhat';
import { RoninGatewayV3__factory } from '../../types';

const deploy = async ({ getNamedAccounts, deployments, ethers }: HardhatRuntimeEnvironment) => {
const { execute } = deployments;
let { governor } = await getNamedAccounts(); // NOTE: Should double check the `governor` account in the `hardhat.config.ts` file
console.log('Governor:', governor);

// const RoninGatewayProxy = '0x0cf8ff40a508bdbc39fbe1bb679dcba64e65c7df';
const RoninGatewayProxy = await deployments.get('RoninGatewayV3Proxy');
const RoninBridgeManager = await deployments.get('RoninBridgeManager');

const AGGRoninToken = '0x294311a8c37f0744f99eb152c419d4d3d6fec1c7';
const AGGMainchainToken = '0xfb0489e9753b045ddb35e39c6b0cc02ec6b99ac5';

let proposalSegments: ProposalSegmentArguments[] = [
{
...defaultSegment,
target: RoninGatewayProxy.address,

// function mapTokens(
// address[] calldata _roninTokens,
// address[] calldata _mainchainTokens,
// uint256[] calldata _chainIds,
// Token.Standard[] calldata _standards
// )

data: proxyCall(RoninGatewayV3__factory.createInterface().encodeFunctionData('mapTokens', [
[AGGRoninToken],
[AGGMainchainToken],
[1], // Ethereum chainId
[0], // Token.Standard ERC20
])),
}
];

if (await checkProposalGas(RoninBridgeManager.address, ethers.provider, proposalSegments[0])) {
console.log('Not enough gas in the proposal');
return;
}

const blockNumBefore = await ethers.provider.getBlockNumber();
const blockBefore = await ethers.provider.getBlock(blockNumBefore);
const timestampBefore = blockBefore.timestamp;
const proposalExpiryTimestamp = timestampBefore + 3600 * 24 * 10; // expired in 10 days

const tx = await execute(
'RoninBridgeManager',
{ from: governor, log: true },
'propose',

// function propose(
// uint256 _chainId,
// uint256 _expiryTimestamp,
// address[] calldata _targets,
// uint256[] calldata _values,
// bytes[] calldata _calldatas,
// uint256[] calldata _gasAmounts
// )

2020,
proposalExpiryTimestamp, // expiryTimestamp
[...proposalSegments.map((_) => _.target)], // targets
[...proposalSegments.map((_) => _.value)], // values
[...proposalSegments.map((_) => _.data)], // datas
[...proposalSegments.map((_) => _.gasAmount)], // gasAmount
);

console.log(`${explorerUrl[network.name!]}/tx/${tx.transactionHash}`);
};

deploy.tags = ['MapTokenRoninchain'];

export default deploy;
46 changes: 46 additions & 0 deletions src/scripts/upgradeUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { BigNumberish, BytesLike } from 'ethers';
import { TransparentUpgradeableProxyV2__factory } from '../types';
import { Address } from 'hardhat-deploy/dist/types';
import { JsonRpcProvider } from '@ethersproject/providers';

export const proxyInterface = new TransparentUpgradeableProxyV2__factory().interface;

export enum Network {
Testnet = 'ronin-testnet',
Mainnet = 'ronin-mainnet',
Ethereum = 'ethereum',
}

export const proxyCall = (calldata: BytesLike) => proxyInterface.encodeFunctionData('functionDelegateCall', [calldata]);

export interface ProposalSegmentArguments {
target?: Address;
value: BigNumberish;
data?: BytesLike;
gasAmount: BigNumberish;
}

export const defaultSegment: ProposalSegmentArguments = {
gasAmount: 1_000_000,
value: 0,
};

export const explorerUrl = {
[Network.Testnet]: 'https://saigon-app.roninchain.com',
[Network.Mainnet]: 'https://app.roninchain.com',
[Network.Ethereum]: 'https://etherscan.io/',
};

export async function checkProposalGas(from: string, provider: JsonRpcProvider, proposal: ProposalSegmentArguments): Promise<boolean> {
let gas = await provider.estimateGas({
from: from,
to: proposal.target,
data: proposal.data,
value: proposal.value,
})

if (gas > proposal.gasAmount)
return false;

return true;
}
Loading