You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For token swaps it would be very helpful to be able to copy balances from one token contract to another. I tried it out but it doesn't work.
Token1
# LST001balances=Hash(default_value=0)
# LST002metadata=Hash()
@constructdefseed():
# LST001 - MINT SUPPLY to wallet that submits the contractbalances[ctx.caller] =1_000_000# LST002metadata['token_name'] ="MY TOKEN NAME"metadata['token_symbol'] ="TKN"metadata['operator'] =ctx.caller# LST002@exportdefchange_metadata(key: str, value: Any):
assertctx.caller==metadata['operator'], 'Only operator can set metadata!'metadata[key] =value# LST001@exportdeftransfer(amount: float, to: str):
assertamount>0, 'Cannot send negative balances!'assertbalances[ctx.caller] >=amount, 'Not enough coins to send!'balances[ctx.caller] -=amountbalances[to] +=amount# LST001@exportdefapprove(amount: float, to: str):
assertamount>0, 'Cannot send negative balances!'balances[ctx.caller, to] +=amount# LST001@exportdeftransfer_from(amount: float, to: str, main_account: str):
assertamount>0, 'Cannot send negative balances!'assertbalances[main_account, ctx.caller] >=amount, 'Not enough coins approved to send! You have {} and are trying to spend {}'\
.format(balances[main_account, ctx.caller], amount)
assertbalances[main_account] >=amount, 'Not enough coins to send!'balances[main_account, ctx.caller] -=amountbalances[main_account] -=amountbalances[to] +=amount@exportdefexport_balances():
returnbalances.get()
Token2
# LST001balances=Hash(default_value=0)
# LST002metadata=Hash()
@constructdefseed():
# LST001 - MINT SUPPLY to wallet that submits the contractbalances[ctx.caller] =1_000_000# LST002metadata['token_name'] ="MY TOKEN NAME"metadata['token_symbol'] ="TKN"metadata['operator'] =ctx.caller# LST002@exportdefchange_metadata(key: str, value: Any):
assertctx.caller==metadata['operator'], 'Only operator can set metadata!'metadata[key] =value# LST001@exportdeftransfer(amount: float, to: str):
assertamount>0, 'Cannot send negative balances!'assertbalances[ctx.caller] >=amount, 'Not enough coins to send!'balances[ctx.caller] -=amountbalances[to] +=amount# LST001@exportdefapprove(amount: float, to: str):
assertamount>0, 'Cannot send negative balances!'balances[ctx.caller, to] +=amount# LST001@exportdeftransfer_from(amount: float, to: str, main_account: str):
assertamount>0, 'Cannot send negative balances!'assertbalances[main_account, ctx.caller] >=amount, 'Not enough coins approved to send! You have {} and are trying to spend {}'\
.format(balances[main_account, ctx.caller], amount)
assertbalances[main_account] >=amount, 'Not enough coins to send!'balances[main_account, ctx.caller] -=amountbalances[main_account] -=amountbalances[to] +=amount@exportdefimport_balances(token_contract: str):
b=I.import_module(token_contract).export_balances()
balances.set(b.get())
If i execute import_balances() in the Token2 contract by providing the token contract of Token1 the transaction goes through without errors but balances are not copied.
The text was updated successfully, but these errors were encountered:
Endogen
changed the title
Feature Request: Allow passing 'balances' to another contract
Feature Request: Allow copying 'balances' to another contract
Sep 24, 2021
For token swaps it would be very helpful to be able to copy
balances
from one token contract to another. I tried it out but it doesn't work.Token1
Token2
If i execute
import_balances()
in the Token2 contract by providing the token contract of Token1 the transaction goes through without errors but balances are not copied.The text was updated successfully, but these errors were encountered: