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

feat: added overrides in dl core and s3 #396

Merged
merged 1 commit into from
Aug 7, 2024
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/admin/rescueFunds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export const main = async () => {
ETH_ADDRESS,
signer.address,
rescueAmount,
{ ...overrides(parseInt(chainSlug)) }
{ ...(await overrides(parseInt(chainSlug))) }
);
console.log(
`Rescuing ${rescueAmount} from ${contractAddr[index]} on ${chainSlug}: ${tx.hash}`
Expand Down
2 changes: 1 addition & 1 deletion scripts/admin/rotate-owner/1-nominate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const checkAndNominate = async (
if (sendTx) {
console.log(`✨ ${label}: Nominating`);
const tx = await contract.nominateOwner(newOwner, {
...overrides(parseInt(chainSlug)),
...(await overrides(parseInt(chainSlug))),
});
const receipt = await tx.wait();
console.log(`🚀 ${label}: Done: ${receipt.transactionHash}`);
Expand Down
4 changes: 3 additions & 1 deletion scripts/admin/rotate-owner/2-claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ const checkAndClaim = async (

if (sendTx) {
console.log(`✨ ${label}: Claiming`);
const tx = await contract.claimOwner({ ...overrides(parseInt(chainSlug)) });
const tx = await contract.claimOwner({
...(await overrides(parseInt(chainSlug))),
});
const receipt = await tx.wait();
console.log(`🚀 ${label}: Done: ${receipt.transactionHash}`);
} else {
Expand Down
4 changes: 2 additions & 2 deletions scripts/admin/setFees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const main = async () => {
);

const nonce = await switchboard.nextNonce(switchboard.signer.getAddress(), {
...overrides(chain),
...(await overrides(chain)),
});
const digest = keccak256(
defaultAbiCoder.encode(
Expand Down Expand Up @@ -72,7 +72,7 @@ const main = async () => {
switchboardFees,
verificationOverheadFees,
signature,
{ ...overrides(chain) }
{ ...(await overrides(chain)) }
);
console.log(tx.hash);

Expand Down
6 changes: 3 additions & 3 deletions scripts/admin/tripGlobal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const main = async () => {
newTripStatus: !tripStatus,
signature,
nonce,
...overrides(chain),
...(await overrides(chain)),
});

if (sendTx) {
Expand All @@ -147,11 +147,11 @@ const sendTxn = async (
let tx;
if (trip)
tx = await switchboard.tripGlobal(nonce, signature, {
...overrides(chain),
...(await overrides(chain)),
});
if (untrip)
tx = await switchboard.unTrip(nonce, signature, {
...overrides(chain),
...(await overrides(chain)),
});
console.log(tx.hash);

Expand Down
4 changes: 2 additions & 2 deletions scripts/admin/untripPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const main = async () => {
newTripStatus: !tripStatus,
signature,
nonce,
...overrides(chain),
...(await overrides(chain)),
});

if (sendTx) {
Expand All @@ -138,7 +138,7 @@ const sendTxn = async (
switchboard: Contract
) => {
let tx = await switchboard.unTripPath(nonce, siblingChain, signature, {
...overrides(chain),
...(await overrides(chain)),
});
console.log(tx.hash);

Expand Down
125 changes: 125 additions & 0 deletions scripts/constants/overrides.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { ChainSlug } from "../../src/enums/chainSlug";
import { BigNumber, providers } from "ethers";

const defaultType = 0;

export const chainOverrides: {
[chainSlug in ChainSlug]?: {
type?: number;
gasLimit?: number;
gasPrice?: number;
};
} = {
[ChainSlug.ARBITRUM_SEPOLIA]: {
type: 1,
gasLimit: 50_000_000,
gasPrice: 200_000_000,
},
[ChainSlug.BSC]: {
gasLimit: 6_000_000,
},
[ChainSlug.MAINNET]: {
gasLimit: 6_000_000,
// gasPrice: 5_000_000_000, // calculate in real time
},

[ChainSlug.POLYGON_MAINNET]: {
// gasPrice: 50_000_000_000, // calculate in real time
},
[ChainSlug.SEPOLIA]: {
type: 1,
gasLimit: 2_000_000,
// gasPrice: 50_000_000_000, // calculate in real time
},
[ChainSlug.AEVO_TESTNET]: {
type: 2,
},
[ChainSlug.LYRA_TESTNET]: {
type: 2,
},
[ChainSlug.MODE_TESTNET]: {
type: 1,
gasPrice: 100_000_000,
},
[ChainSlug.MODE]: {
type: 1,
gasLimit: 10_000_000,
gasPrice: 1_000_000,
},

[ChainSlug.SYNDR_SEPOLIA_L3]: {
type: 1,
gasLimit: 500_000_000,
gasPrice: 1_000_000,
},
[ChainSlug.HOOK]: {
gasLimit: 7_000_000,
},
[ChainSlug.REYA_CRONOS]: {
type: 1,
gasPrice: 100_000_000,
},
[ChainSlug.REYA]: {
type: 1,
gasPrice: 100_000_000,
},
[ChainSlug.POLYNOMIAL_TESTNET]: {
gasLimit: 4_000_000,
},
[ChainSlug.BOB]: {
type: 1,
gasLimit: 4_000_000,
gasPrice: 100_000_000,
},
[ChainSlug.KINTO]: {
gasLimit: 4_000_000,
},
[ChainSlug.KINTO_DEVNET]: {
gasLimit: 4_000_000,
},
[ChainSlug.MANTLE]: {
type: 1,
gasLimit: 100_000_000_000,
gasPrice: 30_000_000,
},
[ChainSlug.NEOX_TESTNET]: {
type: 1,
gasLimit: 1_000_000,
gasPrice: 212_000_000_000,
},
};

export const getOverrides = async (
chainSlug: ChainSlug,
provider: providers.StaticJsonRpcProvider
) => {
let overrides = chainOverrides[chainSlug];
let gasPrice = overrides?.gasPrice;
let gasLimit = overrides?.gasLimit;
let type = overrides?.type;
if (!gasPrice) gasPrice = (await getGasPrice(chainSlug, provider)).toNumber();
if (type == undefined) type = defaultType;
// if gas limit is undefined, ethers will calcuate it automatically. If want to override,
// add in the overrides object. Dont set a default value
return { gasLimit, gasPrice, type };
};

export const getGasPrice = async (
chainSlug: ChainSlug,
provider: providers.StaticJsonRpcProvider
): Promise<BigNumber> => {
let gasPrice = await provider.getGasPrice();

if (chainSlug === ChainSlug.POLYGON_MAINNET) {
return gasPrice.mul(BigNumber.from(115)).div(BigNumber.from(100));
}

if ([ChainSlug.MAINNET].includes(chainSlug as ChainSlug)) {
return gasPrice.mul(BigNumber.from(105)).div(BigNumber.from(100));
}

if ([ChainSlug.SEPOLIA].includes(chainSlug as ChainSlug)) {
return gasPrice.mul(BigNumber.from(150)).div(BigNumber.from(100));
}
return gasPrice;
};
Loading
Loading