-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
123 lines (104 loc) · 5.25 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//using System;
//using System.Numerics;
//using Arbitrum.AssetBridger;
//using Arbitrum.DataEntities;
//using Arbitrum.Utils;
//using Microsoft.Extensions.Configuration;
//using Nethereum.ABI.FunctionEncoding.Attributes;
//using Nethereum.Contracts;
//using Nethereum.Contracts.ContractHandlers;
//using Nethereum.Contracts.Standards.ERC20;
//using Nethereum.Hex.HexConvertors.Extensions;
//using Nethereum.Hex.HexTypes;
//using Nethereum.Web3;
//using Nethereum.Web3.Accounts;
//using SharedSettings;
//using static System.Runtime.InteropServices.JavaScript.JSType;
//class Program
//{
// static async void Main(string[] args)
// {
// IConfiguration configuration = ConfigurationHelper.LoadConfiguration();
// // Read values from appsettings.json
// var devnetPrivKey = configuration["DevelopmentSettings:DEVNET_PRIVKEY"];
// var l1Rpc = configuration["DevelopmentSettings:L1RPC"];
// var l2Rpc = configuration["DevelopmentSettings:L2RPC"];
// var l1Web3 = new Web3(new Account(devnetPrivKey), l1Rpc);
// var l2Web3 = new Web3(new Account(devnetPrivKey), l2Rpc);
// var tokenAmount = BigInteger.Parse("50");
// var tokenAmountToWithdraw = BigInteger.Parse("20");
// Console.WriteLine("Deploying the test DappToken to L1:");
// // Deploy DappToken to L1
// var dappTokenDeployment = new DappTokenDeployment
// {
// InitialSupply = BigInteger.Parse("1000000000000000")
// };
// var l1DappTokenService = await DappTokenService.DeployContractAndGetServiceAsync(l1Web3, dappTokenDeployment);
// var l1DappTokenAddress = l1DappTokenService.ContractHandler.ContractAddress;
// Console.WriteLine($"DappToken is deployed to L1 at {l1DappTokenAddress}");
// // Get L2 network and create an Erc20Bridger instance
// var l2Network = await NetworkUtils.GetL2Network(l2Rpc);
// var erc20Bridger = new Erc20Bridger(l2Network);
// // Adjust token amounts based on decimals
// var tokenDecimals = await l1DappTokenService.DecimalsQueryAsync();
// var tokenDepositAmount = tokenAmount * BigInteger.Pow(10, (int)tokenDecimals);
// var tokenWithdrawAmount = tokenAmountToWithdraw * BigInteger.Pow(10, (int)tokenDecimals);
// // Approve the token for transfer
// Console.WriteLine("Approving:");
// var approveFunction = new ApproveFunction
// {
// Spender = erc20Bridger.StandardGatewayAddress,
// Value = tokenDepositAmount
// };
// var approveReceipt = await l1DappTokenService.ContractHandler.SendRequestAndWaitForReceiptAsync(approveFunction);
// Console.WriteLine($"You successfully allowed the Arbitrum Bridge to spend DappToken {approveReceipt.TransactionHash}");
// // Deposit token to L2
// Console.WriteLine("Transferring DappToken to L2:");
// var depositResult = await erc20Bridger.Deposit(l1DappTokenAddress, l1Web3, l2Rpc, tokenDepositAmount);
// Console.WriteLine($"Deposit initiated: waiting for L2 retryable (takes 10-15 minutes; current time: {DateTime.Now.ToLongTimeString()})");
// var l2Result = await depositResult.WaitForL2CompletionAsync(l2Rpc);
// if (l2Result.Complete)
// {
// Console.WriteLine($"L2 message successful: status: {l2Result.Status}");
// }
// else
// {
// Console.WriteLine($"L2 message failed: status {l2Result.Status}");
// }
// // Withdraw token from L2
// Console.WriteLine("Withdrawing:");
// var withdrawResult = await erc20Bridger.Withdraw(l1DappTokenAddress, l2Rpc, devnetPrivKey, tokenWithdrawAmount);
// Console.WriteLine($"Token withdrawal initiated! 🥳 {withdrawResult.TransactionHash}");
// // Check L2 wallet balance
// var l2TokenAddress = await erc20Bridger.GetL2ERC20Address(l1DappTokenAddress, l1Rpc);
// var l2TokenService = new ERC20Service(l2Web3, l2TokenAddress);
// var l2WalletBalance = await l2TokenService.BalanceOfQuery(l2Web3.TransactionManager.Account.Address);
// if (l2WalletBalance + tokenWithdrawAmount == tokenDepositAmount)
// {
// Console.WriteLine("Token withdraw balance is correct");
// }
// else
// {
// Console.WriteLine("Token withdraw balance is incorrect");
// }
// Console.WriteLine("To claim funds (after dispute period), see outbox-execute repo 🤞🏻");
// }
// // Assuming you have DappTokenDeployment and DappTokenService classes generated by Nethereum for your DappToken contract
// public class DappTokenDeployment : ContractDeploymentMessage
// {
// public static string BYTECODE = "0x..."; // Your contract bytecode
// public DappTokenDeployment() : base(BYTECODE) { }
// public BigInteger InitialSupply { get; set; }
// }
// public class DappTokenService
// {
// public static Task<DappTokenService> DeployContractAndGetServiceAsync(Web3 web3, DappTokenDeployment deployment)
// {
// // Implementation for deploying the contract and getting the service instance
// }
// public Task<uint> DecimalsQuery()
// {
// // Implementation for querying the decimals of the token
// }
// }
//}