π€ΉSupport Multiple Standards
In the case of trying to support multiple standards dynamically, you simply have to call a wrapper function where you want to support both dynamically and pattern match.
For the equivalent of bankkeeper.SendCoins() with our MsgTransferTokens, we provide the SendCoinsWithBadgesRouting function in the keeper itself. Simply call this using the badgeslp:collectionID:pathdenom alias, and it will handle all for you.
// SendCoinsWithBadgesRouting(ctx, bk, 'bb1..', 'bb1...', []{ amount: 100, denom: 'badgeslp:73:utoken' })
func (k Keeper) SendCoinsWithBadgesRouting(ctx sdk.Context, bankKeeper types.BankKeeper, from sdk.AccAddress, to sdk.AccAddress, coins sdk.Coins)
// Couple notes:
// 1. Only pattern matches to bk.SendCoins or our MsgTransferTokens.
// 2. No advanced flows like FundCommunityPool(), SendCoinsFromModuleToAccount()
// 3. User-level approvals are not handled.
// 4. Only auto-scannable approvals are checked for our MsgTransferTokens (no explicitly prioritized)
// 5. Even though we use sdk.Coins[] as parameter, there is no wrapping done. It is just an alias and always uses our standard natively.
// If you need other functionality, consider writing your own which is also very easy (see below).Behind the scenes, this works as follows
Use an alias system. For our liquidity pools we use badgeslp:collectionId:denom format. The denom + collection ID corresponds to the
cosmosCoinWrapperPathselement of the collection with that ID and denom matching the denom.The path element provides details about the conversion rate amounts. Handle the conversion (int amount -> Balance[] array).
Create a wrapped function like below where for each coin, you handle accordingly with your alias system. If it matches the alias, you use our standard and
MsgTransferTokens. If not, use standard x/bank or whatever standard.Anywhere you want to support both dynamically, call the wrapper function instead of your
SendCoinsor other token transfer functionality.
Note that depending on the execution context, your module, contract, etc may not have "forceful" permissions and may be treated as a normal user who has to set its user-level approvals. Handle these accordingly to ensure that the transfers will pass compliance and transferability.
Last updated