Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solana Playground "Seahorse Faucet" error : "A seeds constraint was violated." #111

Open
FahadSalamatRandhawa opened this issue May 17, 2024 · 0 comments

Comments

@FahadSalamatRandhawa
Copy link

Following the tutorials on Solana Playground. The goal is to create a contract that will send others some tokens when requested.
I am following the tutorial exactly but I keep getting this error, I have tried changing stuff but no avail. init_faucet gives the error (its the only one I am trying to test right now)
----------------- Seahorse CODE ---------

from seahorse.prelude import *
from seahorse.pyth import *

declare_id('4kNg32e3FurYQwK4nRH2cXruj2HZDkTWi9c8TL2c7jT5')

class BitcornFaucet(Account):
bump: u8
owner: Pubkey
mint: Pubkey
last_withdraw: i64 # timestamp

@Instruction
def init_faucet(
signer: Signer,
mint: TokenMint,
faucet: Empty[BitcornFaucet],
faucet_account: Empty[TokenAccount]):

bump = faucet.bump()

faucet = faucet.init(
payer = signer,
seeds = ['mint', mint]
)

faucet_account.init(
payer = signer,
seeds = ["token-seed", mint],
mint = mint,
authority = faucet,
)

faucet.bump = bump
faucet.mint = mint.key()
faucet.owner = signer.key()

drips tokens based on the oracle price of BTC

@Instruction
def drip_bitcorn_tokens(
signer: Signer,
mint: TokenMint,
faucet: BitcornFaucet,
faucet_account: TokenAccount,
user_account: TokenAccount,
bitcoin_price_account: PriceAccount,
clock: Clock):

timestamp: i64 = clock.unix_timestamp()

assert mint.key() == faucet.mint, 'Faucet token does not match the token provided'
assert timestamp - 30 > faucet.last_withdraw, 'Please try again in 30 seconds'

btc_price_feed = bitcoin_price_account.validate_price_feed('devnet-BTC/USD')
btc_price = u64(btc_price_feed.get_price().price)
btc_price = btc_price // 100_000_000 # converts to dollar units i.e. 4313965499999 -> 43,139

print("The Bitcorn price is ", btc_price)

thousand_bucks = 1000 * 1_000_000_000
drip_amount = u64(thousand_bucks // btc_price)

bump = faucet.bump

faucet_account.transfer(
authority = faucet,
to = user_account,
amount = u64(drip_amount),
signer = ['mint', mint, bump]
)

send tokens back to replenish the faucet

@Instruction
def replenish_bitcorn_tokens(
signer: Signer,
mint: TokenMint,
user_account: TokenAccount,
faucet_account:
TokenAccount,
amount: u64):

user_account.transfer(
authority = signer,
to = faucet_account,
amount = u64(amount)
)

-----------Inputs--------
signer : 6LC1rBqxjEUnTv1iUQ46pdjQH9hNuoJsbUq6jffMfFM6
mint : HAgxZX4DKW9u7ZbvG782zhScGLLZecNCv389pBAsNj4w (token I minted)
faucet : CatovpWXj4ce9QhSTD1VmmPKjyg1ysrgUBGNBg7nMBvc (random)
faucetAccount : 6VwuiXxMMuMs2Vzszct433v7e7R6NvXaAmwvpjTrFLzX (random)
rent : SysvarRent111111111111111111111111111111111
systemProgram : 11111111111111111111111111111111
tokenProgram : TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant