Skip to content

Commit 6c0ac9b

Browse files
committed
cheeky commit. needs to be reverted
1 parent f158351 commit 6c0ac9b

1 file changed

Lines changed: 55 additions & 60 deletions

File tree

script/utils/fees-manager.ts

Lines changed: 55 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -54,48 +54,51 @@ export async function depositFunds(
5454
evmxChain: ChainConfig
5555
): Promise<void> {
5656
console.log(`${COLORS.CYAN}Depositing funds${COLORS.NC}`);
57-
// TODO: Check balance on FeesPlug and then EVMx
58-
// if not 100 credits : mint missing credits
59-
// if 100 or more transfer to new appgateway
6057

61-
const erc20Abi = parseAbi([
62-
'function mint(address to, uint256 amount) external',
63-
'function approve(address spender, uint256 amount) external returns (bool)'
64-
]);
58+
const balance = await evmxChain.client.getBalance({
59+
address: evmxChain.walletClient.account?.address as Address,
60+
}) as bigint;
6561

66-
const feesPlugAbi = parseAbi([
67-
'function depositCreditAndNative(address token, address appGateway, uint256 amount) external'
62+
const feesAbi = parseAbi([
63+
'function depositCreditAndNative(address token, address appGateway, uint256 amount) external',
64+
'function wrap(address appGateway)'
6865
]);
6966

70-
const walletAddress = arbChain.walletClient.account?.address;
71-
if (!walletAddress) throw new Error('Wallet address not found');
72-
73-
// Mint test USDC
74-
await sendTransaction(
75-
process.env.ARBITRUM_TEST_USDC as Address,
76-
'mint',
77-
[walletAddress, AMOUNTS.TEST_USDC],
78-
arbChain,
79-
erc20Abi
80-
);
81-
82-
// Approve USDC for FeesPlug
83-
await sendTransaction(
84-
process.env.ARBITRUM_TEST_USDC as Address,
85-
'approve',
86-
[process.env.ARBITRUM_FEES_PLUG as Address, AMOUNTS.TEST_USDC],
87-
arbChain,
88-
erc20Abi
89-
);
67+
if (balance > 0n) {
68+
sendTransaction(
69+
process.env.FEES_MANAGER as Address,
70+
'wrap',
71+
[appGateway],
72+
evmxChain,
73+
feesAbi,
74+
parseEther('10')
75+
);
76+
}
9077

91-
// Deposit funds
92-
await sendTransaction(
93-
process.env.ARBITRUM_FEES_PLUG as Address,
94-
'depositCreditAndNative',
95-
[process.env.ARBITRUM_TEST_USDC as Address, appGateway, AMOUNTS.TEST_USDC],
96-
arbChain,
97-
feesPlugAbi
98-
);
78+
//const erc20Abi = parseAbi([
79+
// 'function approve(address spender, uint256 amount) external returns (bool)'
80+
//]);
81+
82+
//const walletAddress = arbChain.walletClient.account?.address;
83+
//if (!walletAddress) throw new Error('Wallet address not found');
84+
85+
//// Approve USDC for FeesPlug
86+
//await sendTransaction(
87+
// process.env.ARBITRUM_USDC as Address,
88+
// 'approve',
89+
// [process.env.ARBITRUM_FEES_PLUG as Address, AMOUNTS.TEST_USDC],
90+
// arbChain,
91+
// erc20Abi
92+
//);
93+
94+
//// Deposit funds
95+
//await sendTransaction(
96+
// process.env.ARBITRUM_FEES_PLUG as Address,
97+
// 'depositCreditAndNative',
98+
// [process.env.ARBITRUM_USDC as Address, appGateway, AMOUNTS.TEST_USDC],
99+
// arbChain,
100+
// feesPlugAbi
101+
//);
99102

100103
await checkAvailableFees(appGateway, evmxChain);
101104
}
@@ -116,36 +119,28 @@ export async function withdrawFunds(
116119
}
117120

118121
const abi = parseAbi([
119-
'function maxFees() external returns (uint256)',
120122
'function withdrawCredits(uint32 chainId, address token, uint256 amount, address to) external',
121123
'function transferCredits(address to_, uint256 amount_) external'
122124
]);
123125

124-
const maxFees = await evmxChain.client.readContract({
125-
address: appGateway,
126-
abi,
127-
functionName: 'maxFees',
128-
});
129-
console.log(`Max fees ${formatEther(maxFees)} Credits - ${maxFees} wei`);
126+
//let amountToWithdraw = availableFees - AMOUNTS.DEPLOY_FEES;
130127

131-
let amountToWithdraw = availableFees - AMOUNTS.DEPLOY_FEES;
128+
//console.log(`Withdrawing ${formatEther(amountToWithdraw)} Credits - ${amountToWithdraw} wei`);
132129

133-
console.log(`Withdrawing ${formatEther(amountToWithdraw)} Credits - ${amountToWithdraw} wei`);
134-
135-
if (amountToWithdraw > 0n) {
136-
await sendTransaction(
137-
appGateway,
138-
'withdrawCredits',
139-
[CHAIN_IDS.ARB_SEP, process.env.ARBITRUM_TEST_USDC, amountToWithdraw, arbChain.walletClient.account?.address],
140-
evmxChain,
141-
abi
142-
);
143-
} else {
144-
console.log('No funds available for withdrawal after gas cost estimation.');
145-
}
130+
//if (amountToWithdraw > 0n) {
131+
// await sendTransaction(
132+
// appGateway,
133+
// 'withdrawCredits',
134+
// [CHAIN_IDS.ARB_SEP, process.env.ARBITRUM_USDC, amountToWithdraw, arbChain.walletClient.account?.address],
135+
// evmxChain,
136+
// abi
137+
// );
138+
//} else {
139+
// console.log('No funds available for withdrawal after gas cost estimation.');
140+
//}
146141

147-
// transfer the rest to the EOA
148-
availableFees = await checkAvailableFees(appGateway, evmxChain);
142+
//// transfer the rest to the EOA
143+
//availableFees = await checkAvailableFees(appGateway, evmxChain);
149144

150145
await sendTransaction(
151146
appGateway,

0 commit comments

Comments
 (0)