When working with a token recently, I did the following:
$ soroban lab token wrap --network futurenet --source default --asset "EXT:$(soroban config identity address default)"
SUCCESS
b528a3f9235cc912c64e5a07d78ec5d634d8be46cde582f9298d337406ecfd5c
$ soroban contract invoke \
--network futurenet \
--source default \
--id b528a3f9235cc912c64e5a07d78ec5d634d8be46cde582f9298d337406ecfd5c \
-- \
xfer \
--to $FREIGHTER_ADDRESS \
--from $(soroban config identity address default) \
--amount 100
error: transaction simulation failed: HostError
Value: Status(ContractError(13))
Debug events (newest first):
0: "Debug trustline missing"
[...]
This makes sense, as the freighter wallet I was sending the tokens to has no trustline for this asset. But afaict there's not really a way to create the trustline from freighter or soroban-cli (without writing code).
Maybe laboratory could help, or maybe we should add a subcommand to soroban-cli, but, this got me thinking about a wider scenario of "send a new token to the user". This would be common in the case of any on-chain swaps where you deposit X and receive new token Y in exchange.
Currently for this scenario, you'd need to do two transactions:
- create trustline for Y with a classic op.
- call the swap contract to do the swap: e.g.
pool.swap(x, y)
This is a similar flow to the old approve&transfer_from workflow which auth-next helps us avoid.
Proposal 1
Should the standard asset contract have an create_trustline(user, asset) method?
It could idempotently ensure that the user has a trustline for the given asset, and could be callable only by user.
In that case auth-next would allow the pool.swap(x, y) to call create_trustline on behalf of the user with delegation, like the tranfer_from workflow is now.
Proposal 2
More radical suggestion: Should transfer and transfer_from auto-create a trustline?