@@ -17,7 +17,7 @@ func (s *DBImpl) SubBalance(evmAddr common.Address, amt *big.Int) {
17
17
return
18
18
}
19
19
20
- s .err = s . k . BankKeeper (). SendCoinsWithoutAccCreation ( s . ctx , s . getSeiAddress (evmAddr ), s .middleManAddress , s . bigIntAmtToCoins ( amt ) )
20
+ s .send ( s . getSeiAddress (evmAddr ), s .middleManAddress , amt )
21
21
}
22
22
23
23
func (s * DBImpl ) AddBalance (evmAddr common.Address , amt * big.Int ) {
@@ -29,32 +29,34 @@ func (s *DBImpl) AddBalance(evmAddr common.Address, amt *big.Int) {
29
29
return
30
30
}
31
31
32
- s .err = s . k . BankKeeper (). SendCoinsWithoutAccCreation ( s . ctx , s . middleManAddress , s .getSeiAddress (evmAddr ), s . bigIntAmtToCoins ( amt ) )
32
+ s .send ( s . middleManAddress , s .getSeiAddress (evmAddr ), amt )
33
33
}
34
34
35
35
func (s * DBImpl ) GetBalance (evmAddr common.Address ) * big.Int {
36
- return s .coinToBigIntAmt (s .k .BankKeeper ().GetBalance (s .ctx , s .getSeiAddress (evmAddr ), s .k .GetBaseDenom (s .ctx )))
36
+ usei := s .k .BankKeeper ().GetBalance (s .ctx , s .getSeiAddress (evmAddr ), s .k .GetBaseDenom (s .ctx )).Amount
37
+ wei := s .k .BankKeeper ().GetWeiBalance (s .ctx , s .getSeiAddress (evmAddr ))
38
+ return usei .Mul (sdk .NewIntFromBigInt (UseiToSweiMultiplier )).Add (wei ).BigInt ()
37
39
}
38
40
39
41
// should only be called during simulation
40
42
func (s * DBImpl ) SetBalance (evmAddr common.Address , amt * big.Int ) {
41
43
if ! s .simulation {
42
44
panic ("should never call SetBalance in a non-simulation setting" )
43
45
}
44
- // Fields that were denominated in usei will be converted to swei (1usei = 10^12swei)
45
- // for existing Ethereum application (which assumes 18 decimal points) to display properly.
46
- amt = new (big.Int ).Quo (amt , UseiToSweiMultiplier )
47
46
seiAddr := s .getSeiAddress (evmAddr )
48
- balance := s .k .BankKeeper ().GetBalance (s .ctx , seiAddr , s .k .GetBaseDenom (s .ctx ))
49
- if err := s .k .BankKeeper ().SendCoinsFromAccountToModule (s .ctx , seiAddr , types .ModuleName , sdk .NewCoins (balance )); err != nil {
50
- panic (err )
47
+ moduleAddr := s .k .AccountKeeper ().GetModuleAddress (types .ModuleName )
48
+ s .send (seiAddr , moduleAddr , s .GetBalance (evmAddr ))
49
+ if s .err != nil {
50
+ panic (s .err )
51
51
}
52
- coinsAmt := sdk .NewCoins (sdk .NewCoin (s .k .GetBaseDenom (s .ctx ), sdk .NewIntFromBigInt (amt )))
52
+ usei , _ := SplitUseiWeiAmount (amt )
53
+ coinsAmt := sdk .NewCoins (sdk .NewCoin (s .k .GetBaseDenom (s .ctx ), sdk .NewIntFromBigInt (usei ).Add (sdk .OneInt ())))
53
54
if err := s .k .BankKeeper ().MintCoins (s .ctx , types .ModuleName , coinsAmt ); err != nil {
54
55
panic (err )
55
56
}
56
- if err := s .k .BankKeeper ().SendCoinsFromModuleToAccount (s .ctx , types .ModuleName , seiAddr , coinsAmt ); err != nil {
57
- panic (err )
57
+ s .send (moduleAddr , seiAddr , amt )
58
+ if s .err != nil {
59
+ panic (s .err )
58
60
}
59
61
}
60
62
@@ -69,14 +71,7 @@ func (s *DBImpl) getSeiAddress(evmAddr common.Address) (seiAddr sdk.AccAddress)
69
71
return
70
72
}
71
73
72
- func (s * DBImpl ) bigIntAmtToCoins (amt * big.Int ) sdk.Coins {
73
- // Fields that were denominated in usei will be converted to swei (1usei = 10^12swei)
74
- // for existing Ethereum application (which assumes 18 decimal points) to display properly.
75
- amt = new (big.Int ).Quo (amt , UseiToSweiMultiplier )
76
- return sdk .NewCoins (sdk .NewCoin (s .k .GetBaseDenom (s .ctx ), sdk .NewIntFromBigInt (amt )))
77
- }
78
-
79
- func (s * DBImpl ) coinToBigIntAmt (coin sdk.Coin ) * big.Int {
80
- balanceInUsei := coin .Amount .BigInt ()
81
- return new (big.Int ).Mul (balanceInUsei , UseiToSweiMultiplier )
74
+ func (s * DBImpl ) send (from sdk.AccAddress , to sdk.AccAddress , amt * big.Int ) {
75
+ usei , wei := SplitUseiWeiAmount (amt )
76
+ s .err = s .k .BankKeeper ().SendCoinsAndWei (s .ctx , from , to , nil , s .k .GetBaseDenom (s .ctx ), sdk .NewIntFromBigInt (usei ), sdk .NewIntFromBigInt (wei ))
82
77
}
0 commit comments