Is it possible to write a percentage spending permission into a SC

I want to write a timelock contract that the user can set a spend percentage for.
like so

  • connect wallet
  • the user enters the recipient address
  • sets time lock for x amount of seconds (or whatever time unit)
  • user sets 75% of the available token balance when timelock ends
  • approve transaction

So lets say the user has a 100 token balance when they submit the transaction, but then goes to spend some tokens, and now they have 10 tokens. When the transaction executes, it will send 75% of the 10 tokens instead of trying to send 75% of 100 tokens.

Is this possible?

It could be possible to make a custom logic in your smart contract so that an approve is time locked, but it will require two transactions, an initial transactions that approves the spending of those funds after n seconds, and another transaction to effectively transfer those tokens after n seconds.

1 Like

OK, but is it possible to approve the transaction, and give the contract spending permission, but after the countdown ends, it looks at your total balance and calculates the amount to spend from the user set percentage?

after the countdown ends you’ll have to make another transaction, only a transaction can move funds. It doesn’t necessarily have to be done exactly when the count down ends, but without a transaction you can not change the current state of the blockchain.

1 Like

I see. So i guess im not looking for a time locked contract but a time locked transaction. I want the contract to control the wallet and be able to empty the whole thing after its countdown ends, without the user having to go initiate the transaction when the time lock ends.

the user doesn’t have to initiate that transaction, you can do it too, but you need to send a transaction in order to empty that wallet with what it has, the smart contract can control the wallet, but it can not send a transaction by itself.

1 Like

Or you can do it the other way where you make a smart contract that has the token, and you can limit that address to not be able to transfer those tokens any more after a particular time interval passed. (it is a little more complicated then previous option)

1 Like

So i would have to have a JS program do it or something?

you can do it automatically from a server, you will need the private key for an address that it is allowed to call a specific smart contract function that will make that transfer

1 Like

Right… Ok thanks i think that covers what I need to do. this was helpful!