-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TRA-621] Sweep bank funds of megavault into subaccount.
- Loading branch information
1 parent
b37ff5e
commit 716603a
Showing
11 changed files
with
540 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
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 | ||
} | ||
} |
Oops, something went wrong.