Skip to content

Commit

Permalink
working initialize programs
Browse files Browse the repository at this point in the history
  • Loading branch information
guibescos committed Jan 8, 2025
1 parent e50bdbb commit bd03770
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion contracts/svm/programs/express_relay/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct ExpressRelayMetadata {
pub split_router_default: u64,
// the portion of the remaining bid (after router fees) that goes to the relayer, in bps
pub split_relayer: u64,
// the portion of the swap amount that goes to the platform (relayer + express relay), in bps
// the portion of the swap amount that should go to the platform (relayer + express relay), in bps
pub swap_platform_fee_bps: u64,
}

Expand Down
31 changes: 30 additions & 1 deletion tilt-scripts/svm/initialize_programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@
InitializeAccounts,
initialize,
)
from express_relay.svm.generated.express_relay.instructions.set_swap_platform_fee import (
SetSwapPlatformFeeAccounts,
set_swap_platform_fee,
)
from express_relay.svm.generated.express_relay.types.initialize_args import (
InitializeArgs,
)
from express_relay.svm.generated.express_relay.types.set_swap_platform_fee_args import (
SetSwapPlatformFeeArgs,
)
from solana.rpc.async_api import AsyncClient
from solana.rpc.commitment import Confirmed
from solana.transaction import Transaction
Expand Down Expand Up @@ -60,6 +67,13 @@ def parse_args() -> argparse.Namespace:
default=2000,
help="Percentage of remaining bid (post protocol fee) that should go to relayer, in bps",
)
parser.add_argument(
"--swap-platform-fee-bps",
type=int,
required=False,
default=10,
help="The portion of the swap amount that should go to the platform (relayer + express relay), in bps",
)
parser.add_argument(
"--rpc-url",
type=str,
Expand Down Expand Up @@ -97,6 +111,7 @@ async def main():
balance_express_relay_metadata = await client.get_balance(pk_express_relay_metadata)

tx = Transaction()
signers = [kp_admin]
if balance_express_relay_metadata.value == 0:
ix_init_express_relay = initialize(
{
Expand All @@ -114,9 +129,23 @@ async def main():
),
)
tx.add(ix_init_express_relay)
signers.append(kp_payer)

ix_set_swap_platform_fee = set_swap_platform_fee(
{
"data": SetSwapPlatformFeeArgs(
swap_platform_fee_bps=args.split_protocol_default
),
},
SetSwapPlatformFeeAccounts(
admin=pk_admin,
express_relay_metadata=pk_express_relay_metadata,
),
)
tx.add(ix_set_swap_platform_fee)

if len(tx.instructions) > 0:
tx_sig = (await client.send_transaction(tx, kp_payer)).value
tx_sig = (await client.send_transaction(tx, *signers)).value
conf = await client.confirm_transaction(tx_sig)
assert conf.value[0].status is None, "Initialization of programs failed"
logger.info(f"Initialization of programs successful: {tx_sig}")
Expand Down

0 comments on commit bd03770

Please sign in to comment.