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

Fix fees Calculations #313

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@ src/api/marketplace/dump.rdb

# solana-ts
solana-ts-node/node_modules/*

8 changes: 5 additions & 3 deletions solana-client/components/CancelEscrowSpl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,19 @@ interface CancelEscrowSplProps {
business: string,
validatorAuthority: string,
mintTokenAccount: string,
orderCode: number
orderCode: number,
network: string
}

export const CancelEscrowSpl: FC<CancelEscrowSplProps> = (
{business,
validatorAuthority,
mintTokenAccount,
orderCode}) => {
orderCode,
network}) => {

const wallet = useAnchorWallet()
const connection = new Connection(clusterApiUrl('devnet'),
const connection = new Connection(network,
{
commitment: "confirmed",
confirmTransactionInitialTimeout: 30000
Expand Down
2 changes: 2 additions & 0 deletions solana-client/components/CreateEscrowSolana.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export const CreateEscrowSolana: FC<CreateEscrowSolanaProps> = ({validator, busi
commitment: "confirmed",
confirmTransactionInitialTimeout: 30000
});


const program = utils.getAnchorProgram(connection);
const provider = new AnchorProvider(connection, wallet, {})
setProvider(provider)
Expand Down
2 changes: 2 additions & 0 deletions solana-client/components/Validate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export const Validate: FC<ValidateProps> = ({validator,

const program = utils.getAnchorProgram(connection);
const provider = new AnchorProvider(connection, wallet, {})

setProvider(provider)

const { publicKey, signTransaction, sendTransaction } = useWallet()

if (!connection || !publicKey) {
Expand Down
3 changes: 2 additions & 1 deletion solana-client/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ const Home: NextPage = (props) => {
<CancelEscrowSpl business={BUSINESS}
validatorAuthority={VALIDATOR}
mintTokenAccount={MINT}
orderCode={ORDER_CODE} />
orderCode={ORDER_CODE}
network={NETWORK} />

<ValidateEscrowSpl
validator={VALIDATOR}
Expand Down
22 changes: 22 additions & 0 deletions solana-python/anchorpy_dynamic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from pathlib import Path
import asyncio
import json
from solders.pubkey import Pubkey
from anchorpy import Idl, Program

async def main():
# Read the generated IDL.
with Path("xfluencer.json").open() as f:
raw_idl = f.read()
idl = Idl.from_json(raw_idl)
# Address of the deployed program.
program_id = Pubkey.from_string(idl.metadata['address'])
# Generate the program client from IDL.
async with Program(idl, program_id) as program:
# Execute the RPC.
await program.rpc["initialize"]()
# If we don't use the context manager, we need to
# close the underlying http client, otherwise we get warnings.
await program.close()

asyncio.run(main())
10 changes: 6 additions & 4 deletions solana-python/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"network": "https://devnet.helius-rpc.com/?api-key=b57191c8-c14e-4ae2-83b6-1ab88c2f3605",
"network": "https://mainnet.helius-rpc.com/?api-key=b57191c8-c14e-4ae2-83b6-1ab88c2f3605",
"network-dev":"https://devnet.helius-rpc.com/?api-key=b57191c8-c14e-4ae2-83b6-1ab88c2f3605",
"rpc":{
"mainnet":"https://bold-hidden-glade.solana-mainnet.quiknode.pro/bcd715dccef5e699ea43459b691a09c2bc8dc474",
"devnet":""
Expand All @@ -10,7 +11,7 @@
"usdc_ata_localnet": "8TkaDh6WGExnXpvBeoCPwY9XNNd7dK3Nn5W3y1Q2djJV"
},
"business": {
"pubkey":"GQRDv58u1dULSyHSYWPqNTjcWjsFHHi763mbqDaEEgQ3",
"pubkey":"6suvWCcjg5o7xgHrDGc4MXQxraK9PnZyEXzjhhQN6HUK",
"usdc_ata": "B8LnJbxHoDzcA7GCTz3C9H819sqVe8Ro51WMJDGLZHCe",
"usdc_ata_localnet": "75toiYLG8AiEktDnYMwToHZ3RJrkpiSyapWknv9yTVs9"
},
Expand All @@ -28,8 +29,8 @@
},
"platform": "EsYxpj9ADJyGEjMv3tyDpADv33jDPkv9uLymXWwQCiwH",
"amount":{
"lamports":10000000,
"usdc": 1000000
"lamports":10000,
"usdc": 1
},
"order_code": 36831,
"program_id":{
Expand All @@ -40,3 +41,4 @@
"mainnet": "DmYaabL1PhacWWsRwyZpBqBP9n7tVq7115zG2tznYLb9"
}
}
g
11 changes: 9 additions & 2 deletions solana-python/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,30 @@ def load_configuration(config_file="config.json"):


configuration = load_configuration()
program_id = configuration["program_id"]["devnet"]
program_id = configuration["program_id"]["mainnet"]
print("Program Id Selected From Configuration:", program_id)
PROGRAM_ID = Pubkey.from_string(program_id)


@dataclass
class KeypairPaths:
home: str = os.getenv("HOME") + "/influencer-marketplace/solana-python/test_wallets"

platform: str = "platform_EsYxpj9ADJyGEjMv3tyDpADv33jDPkv9uLymXWwQCiwH.json"
validation_authority: str = f"{home}/{platform}"

business: str = "business_6suvWCcjg5o7xgHrDGc4MXQxraK9PnZyEXzjhhQN6HUK.json"
bussines_keypair: str = f"{home}/{business}"

influencer: str = "influencer_94fznXq73oweXLrg2zL75XAMy9xNEbqtb191Xcrq97QA.json"
influencer_keypair: str = f"{home}/{influencer}"






@dataclass
class SplTokens:
usdc: str = "Gh9ZwEmdLJ8DscKNTkTqPbNwLNNBjuSzaG9Vp2KGtKJr"
usdc_alt: str = "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU"
usdc_alt: str = "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU"
19 changes: 12 additions & 7 deletions solana-python/launch_cancel_escrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@

from pyxfluencer.instructions import cancel_escrow_sol

async def main():

msg = "Cancel Escrow Amount by Business"
def print_tittle(msg):
print(len(msg)*"*")
print(msg)
print(len(msg)*"*")

async def main():

msg = "Cancel Escrow Amount by Business"
print_tittle(msg)

configuration = load_configuration()
network = configuration["network"]
Expand All @@ -26,10 +29,12 @@ async def main():
keypair_paths = KeypairPaths()

business, business_pk = get_local_keypair_pubkey(path=keypair_paths.bussines_keypair)
#business, business_pk = get_local_keypair_pubkey()

_, influencer_pk = get_local_keypair_pubkey(path=keypair_paths.influencer_keypair)

assert str(business_pk) == configuration["business"]
assert str(influencer_pk) == configuration["influencer"]
assert str(business_pk) == configuration["business"]["pubkey"]
assert str(influencer_pk) == configuration["influencer"]["pubkey"]

order_code = configuration["order_code"]

Expand All @@ -48,8 +53,8 @@ async def main():
"escrow_account":escrow_pda}

ix = cancel_escrow_sol(accounts)
opts = TxOpts(skip_confirmation = True,
skip_preflight = True)
opts = TxOpts(skip_confirmation = False,
skip_preflight = False)

signers = [business]

Expand Down
10 changes: 5 additions & 5 deletions solana-python/launch_claim_escrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ async def main():

# implement caller to claim escrow instruction
configuration = load_configuration()
network = configuration["network"]
network = configuration["rpc"]["mainnet"]

print(f"Network: {network} Program ID: {PROGRAM_ID}")

keypair_paths = KeypairPaths()

# do not need keypair from business just the public key
_, business_pk = get_local_keypair_pubkey(path=keypair_paths.bussines_keypair)
_, business_pk = get_local_keypair_pubkey() #path=keypair_paths.bussines_keypair)

# keypair needed here is the one from influcner because it sings the transaction
influencer, influencer_pk = get_local_keypair_pubkey(path=keypair_paths.influencer_keypair)

assert str(business_pk) == configuration["business"]
assert str(influencer_pk) == configuration["influencer"]
assert str(business_pk) == configuration["business"]["pubkey"]
assert str(influencer_pk) == configuration["influencer"]["pubkey"]

order_code = configuration["order_code"]

Expand All @@ -51,7 +51,7 @@ async def main():

ix = claim_escrow(args, accounts, program_id=PROGRAM_ID)
opts = TxOpts(skip_confirmation = True,
skip_preflight = True)
skip_preflight = False)

signers = [influencer]

Expand Down
101 changes: 86 additions & 15 deletions solana-python/launch_create_escrow.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
from solders.pubkey import Pubkey
from solana.rpc.types import TxOpts

from pyxfluencer.utils import get_local_keypair_pubkey
from pathlib import Path
from solders.pubkey import Pubkey # type: ignore
from anchorpy import Idl, Program

import asyncio
from solders.system_program import ID as SYS_PROGRAM_ID


from pyxfluencer.utils import get_local_keypair_pubkey, select_client
from pyxfluencer.utils import sign_and_send_transaction
from pyxfluencer.program_id import PROGRAM_ID

from pyxfluencer.instructions import create_escrow

from config import KeypairPaths, load_configuration

async def main():


msg = "Create Escrow for Business and Influencer with an amount and an order code"
def print_tittle(msg):
print(len(msg)*"*")
print(msg)
print(len(msg)*"*")

async def main():

msg = "Create Escrow for Business and Influencer with an amount and an order code"
print_tittle(msg)

configuration = load_configuration()

network = configuration["rpc"]["mainnet"]

print(f"Network: {network}")
print("Network selected: ",network)
client = select_client(network=network, async_client=False)


print(f"Program ID: {PROGRAM_ID}")

keypair_paths = KeypairPaths()
Expand All @@ -38,11 +50,28 @@ async def main():
assert str(business_pk) == configuration["business"]["pubkey"]
assert str(influencer_pk) == configuration["influencer"]["pubkey"]

### get account info on tx accounts before sending it
accounts = [validation_authority_pk,
business_pk,
influencer_pk]

for acc in accounts:
try:
account_info = client.get_account_info(acc)
#print(account_info)
print(f"Sols in {str(acc)}",account_info.value.lamports / 10 ** 8)
except Exception:
print("Account not initialized, cannot continue")
return



amount = configuration["amount"]["lamports"]
order_code = configuration["order_code"]


args = {"amount":int(amount), "order_code":int(order_code)}
args = {"amount":int(amount),
"order_code":int(order_code)}

SEEDS = [b"escrow",
bytes(business_pk),
Expand All @@ -59,19 +88,61 @@ async def main():
"to":influencer_pk
}

opts = TxOpts(skip_confirmation = True,
skip_preflight = True,
client = select_client(network=network, async_client=False)

latest_blockhash = client.get_latest_blockhash().value.last_valid_block_height


opts = TxOpts(skip_confirmation = False,
skip_preflight = False,
max_retries=1,
last_valid_block_height=latest_blockhash,
preflight_commitment="processed")

print_tittle("Instruction description")

ix = create_escrow(args, accounts, program_id=PROGRAM_ID)

signers = [business]
signers = [business]

sign_status = await sign_and_send_transaction(ix, signers, network)
## forming the transaction
from solana.transaction import Transaction
from solana.rpc.core import RPCException
from solders.compute_budget import set_compute_unit_limit, set_compute_unit_price

tx = Transaction(fee_payer=business_pk, recent_blockhash=None) \
.add(set_compute_unit_price(1_000)) \
.add(ix)

print(sign_status)
#sign_status = await sign_and_send_transaction(ix, signers, opts, network)
#sign_status = sign_and_send_transaction_sync(ix, signers, opts, network)

try:
print("Network selected: ",network)
client = select_client(network=network, async_client=False)

#print("Simulate Transaction")
#simulate_response = client.simulate_transaction(tx, sig_verify=True)
#print("Simulate Response", simulate_response)
#print(simulate_response.value.err)

print("Start Sending transactions with options", opts)

tx_res = client.send_transaction(tx, *signers, opts=opts)

print("Client Response tx signature: ", tx_res)

print("Waiting for transaction confirmation")

signature_status = client.confirm_transaction(tx_res.value)

print("Confirm Transaction Status Value:", signature_status)
return signature_status.to_json()
except RPCException as e:
raise RPCException(f"RPC exception happened: {e}")



import asyncio

asyncio.run(main())


8 changes: 7 additions & 1 deletion solana-python/launch_create_escrow_spl.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ async def main():
account_info = await get_token_account_info(ata, network)
print(f"ATA account {ata} --> amount tokens = {account_info.amount}")

business, business_pk = get_local_keypair_pubkey(path=keypair_paths.bussines_keypair)
#business, business_pk = get_local_keypair_pubkey(path=keypair_paths.bussines_keypair)
business, business_pk = get_local_keypair_pubkey(path=keypair_paths.bussines_GQRD)

_, influencer_pk = get_local_keypair_pubkey(path=keypair_paths.influencer_keypair)
_, validation_authority_pk = get_local_keypair_pubkey(path=keypair_paths.validation_authority)

Expand All @@ -71,6 +73,10 @@ async def main():

# find pdas for create escrow with spl
order_code = configuration["order_code"]

print("order code selected:",order_code)



SEEDS = [b"token-seed",
bytes(str(order_code),"UTF-8")]
Expand Down
Loading