from web3 import Web3
CCIP = "0xD99e4B13fc50A6321f6A84f2D4F83d6e34AE699D"
USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
ZERO = "0x" + "0" * 40
SAFE_CONFIG = [{"name": "owners", "type": "address[]"}, {"name": "threshold", "type": "uint256"}]
ASSET_CONFIG = [{"name": "asset", "type": "address"}, {"name": "canDeposit", "type": "bool"}, {"name": "canRedeem", "type": "bool"}]
TIMELOCK_PARAMS = [{"name": "minDelay", "type": "uint256"}, {"name": "proposers", "type": "address[]"},
{"name": "cancellers", "type": "address[]"}]
PARAMS = [
{"name": "asset", "type": "address"}, {"name": "admin", "type": "address"},
{"name": "name", "type": "string"}, {"name": "symbol", "type": "string"}, {"name": "safe", "type": "address"},
{"name": "subscriptionRequestTtl", "type": "uint64"}, {"name": "redemptionRequestTtl", "type": "uint64"},
{"name": "feeReceiver", "type": "address"}, {"name": "managementFeeRate", "type": "uint256"},
{"name": "redemptionFeeRate", "type": "uint256"}, {"name": "performanceFeeModule", "type": "address"},
{"name": "performanceFeeRate", "type": "uint256"},
]
OIV_CONFIG = {"name": "config", "type": "tuple", "components": [
{"name": "managerSafe", "type": "tuple", "components": SAFE_CONFIG},
{"name": "salt", "type": "uint256"}, {"name": "admin", "type": "address"},
{"name": "sharesParams", "type": "tuple", "components": PARAMS},
{"name": "additionalAssets", "type": "tuple[]", "components": ASSET_CONFIG},
{"name": "execTimelock", "type": "tuple", "components": TIMELOCK_PARAMS},
{"name": "sharesTimelock", "type": "tuple", "components": TIMELOCK_PARAMS},
]}
SHARES_CHAINS = {"name": "sharesChains", "type": "tuple[]", "components": [
{"name": "chainId", "type": "uint256"}, {"name": "asset", "type": "address"},
]}
OIV_INSTANCE = [{"name": n, "type": "address"} for n in
["avatarSafe", "managerSafe", "execRolesModifier", "subRolesModifier",
"managerRolesModifier", "kpkSharesImpl", "kpkSharesProxy",
"execTimelock", "sharesTimelock"]]
GAS = {"name": "gasLimit", "type": "uint256"}
ABI = [
{"name": "predictOiv", "type": "function", "stateMutability": "view",
"inputs": [OIV_CONFIG, SHARES_CHAINS], "outputs": [{"name": "", "type": "tuple", "components": OIV_INSTANCE}]},
{"name": "quoteDeployEverywhere", "type": "function", "stateMutability": "view",
"inputs": [OIV_CONFIG, SHARES_CHAINS, GAS],
"outputs": [{"name": "totalFee", "type": "uint256"}, {"name": "feePerDestination", "type": "uint256[]"}]},
{"name": "deployEverywhere", "type": "function", "stateMutability": "payable",
"inputs": [OIV_CONFIG, SHARES_CHAINS, GAS],
"outputs": [{"name": "instance", "type": "tuple", "components": OIV_INSTANCE},
{"name": "messageIds", "type": "bytes32[]"}]},
]
# Every address list must be strictly ascending by value.
timelock = (172800, ["0xSecurityCouncilSafe..."], []) # 2 days; sole proposer, no extra cancellers
config = (
(["0x1111...", "0x2222...", "0x3333..."], 2), # managerSafe (owners, threshold)
1, # salt
"0xAdminSafe...", # admin
(USDC, ZERO, "KPK USD Alpha", "kUSD", ZERO,
86400, 86400, "0xFeeReceiver...", 100, 0, ZERO, 0), # sharesParams
[], # additionalAssets
timelock, # execTimelock
timelock, # sharesTimelock
)
shares_chains = [(1, USDC)] # shares on Ethereum only
GAS_LIMIT = 3_000_000 # timelocked fund
w3 = Web3(Web3.HTTPProvider("https://eth.llamarpc.com"))
orchestrator = w3.eth.contract(address=CCIP, abi=ABI)
predicted = orchestrator.functions.predictOiv(config, shares_chains).call()
print("Portfolio Safe will be:", predicted[0]) # avatarSafe
total_fee, _ = orchestrator.functions.quoteDeployEverywhere(config, shares_chains, GAS_LIMIT).call()
# Deploy: build, sign, and send with a 10% buffer over total_fee (surplus is refunded)
acct = w3.eth.account.from_key("0x<PRIVATE_KEY>")
tx = orchestrator.functions.deployEverywhere(config, shares_chains, GAS_LIMIT).build_transaction({
"from": acct.address, "value": total_fee * 11 // 10, "nonce": w3.eth.get_transaction_count(acct.address),
})
signed = acct.sign_transaction(tx)
print("deployEverywhere tx:", w3.eth.send_raw_transaction(signed.raw_transaction).hex())