forked from axieinfinity/ronin-dpos-contracts
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
], | ||
])), | ||
} | ||
]; | ||
|
||
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBD