-
Notifications
You must be signed in to change notification settings - Fork 101
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
[TRA-621] Sweep bank funds of megavault into subaccount. #2293
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,32 @@ | ||
package types | ||
|
||
import ( | ||
"math/big" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
type AssetsKeeper interface { | ||
ConvertAssetToCoin(ctx sdk.Context, assetId uint32, quantums *big.Int) (*big.Int, sdk.Coin, error) | ||
CreateAsset( | ||
ctx sdk.Context, | ||
assetId uint32, | ||
symbol string, | ||
denom string, | ||
denomExponent int32, | ||
hasMarket bool, | ||
marketId uint32, | ||
atomicResolution int32, | ||
) ( | ||
Asset, | ||
error, | ||
) | ||
|
||
GetAsset(ctx sdk.Context, id uint32) (Asset, bool) | ||
|
||
GetAllAssets(ctx sdk.Context) []Asset | ||
|
||
IsPositionUpdatable(ctx sdk.Context, id uint32) (bool, error) | ||
|
||
ModifyAsset(ctx sdk.Context, id uint32, hasMarket bool, marketId uint32) (Asset, error) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/dydxprotocol/v4-chain/protocol/lib/log" | ||
assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" | ||
"github.com/dydxprotocol/v4-chain/protocol/x/vault/types" | ||
) | ||
|
||
// SweepMainVaultBankBalances deposits any usdc balance from the Megavault main vault bank balance | ||
// into the Megavault main vault subaccount balance. | ||
func (k Keeper) SweepMainVaultBankBalance( | ||
ctx sdk.Context, | ||
) { | ||
usdcAsset, exists := k.assetsKeeper.GetAsset(ctx, assettypes.AssetUsdc.Id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: can also just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Led to a flaky simulation test when I removed it, going to add it back in for now. |
||
if !exists { | ||
log.ErrorLog( | ||
ctx, | ||
"SweepMainVaultBankBalance: Usdc asset not found in state", | ||
) | ||
return | ||
} | ||
mainVaultBalance := k.bankKeeper.GetBalance( | ||
ctx, | ||
types.MegavaultMainAddress, | ||
usdcAsset.Denom, | ||
) | ||
// No funds to sweep | ||
if mainVaultBalance.Amount.BigInt().Sign() <= 0 { | ||
return | ||
} | ||
|
||
err := k.subaccountsKeeper.DepositFundsFromAccountToSubaccount( | ||
ctx, | ||
types.MegavaultMainAddress, | ||
types.MegavaultMainSubaccount, | ||
usdcAsset.Id, | ||
mainVaultBalance.Amount.BigInt(), | ||
) | ||
if err != nil { | ||
log.ErrorLogWithError( | ||
ctx, | ||
"SweepMainVaultBankBalance: Failed to sweep funds from main vault bank balance to subaccount", | ||
err, | ||
) | ||
return | ||
} | ||
} |
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.
Correct the directory path in the mock generation command
The
--dir
argument in the mock generation command contains an extra slash (//
) which may cause issues when generating the mock forAssetsKeeper
. It should point to the correct directory whereAssetsKeeper
is defined.Apply this diff to fix the directory path:
Committable suggestion