-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb5b1c6
commit 6c217db
Showing
1 changed file
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { Client, IsmType } from "../shared/config"; | ||
import { Context, ContextIsm } from "../shared/context"; | ||
import { | ||
deployContract, | ||
executeContract, | ||
executeMultiMsg, | ||
} from "../shared/contract"; | ||
|
||
const deployRoutingIsm = async ( | ||
ctx: Context, | ||
client: Client, | ||
ism: Extract<IsmType, { type: "routing" }> | ||
) => { | ||
const routes = []; | ||
for (const [domain, v] of Object.entries(ism.isms)) { | ||
routes.push({ | ||
domain: parseInt(domain), | ||
route: await deployIsm(ctx, client, v), | ||
}); | ||
} | ||
|
||
const routing = await deployContract(ctx, client, "hpl_ism_routing", { | ||
owner: ism.owner === "<signer>" ? client.signer : ism.owner, | ||
}); | ||
|
||
await executeContract(client, routing, { | ||
router: { | ||
set_routes: { | ||
set: routes.map(({ domain, route }) => ({ | ||
domain, | ||
route: route.address, | ||
})), | ||
}, | ||
}, | ||
}); | ||
|
||
return { | ||
...routing, | ||
isms: routes.reduce((acc, v) => ({ [v.domain]: v.route, ...acc })), | ||
}; | ||
}; | ||
|
||
export async function deployIsm( | ||
ctx: Context, | ||
client: Client, | ||
ism: Exclude<IsmType, number[]> | ||
): Promise<ContextIsm> { | ||
switch (ism.type) { | ||
// deploy multisig ism | ||
case "multisig": | ||
const multisig = await deployContract(ctx, client, "hpl_ism_multisig", { | ||
owner: ism.owner === "<signer>" ? client.signer : ism.owner, | ||
}); | ||
|
||
await executeMultiMsg( | ||
client, | ||
Object.entries(ism.validators).map( | ||
([domain, { addrs, threshold }]) => ({ | ||
contract: multisig, | ||
msg: { | ||
set_validators: { | ||
domain: Number(domain), | ||
threshold, | ||
validators: addrs, | ||
}, | ||
}, | ||
}) | ||
) | ||
); | ||
|
||
return multisig; | ||
|
||
// deploy aggregate ism | ||
case "aggregate": | ||
const aggr = []; | ||
for (const v of ism.isms) { | ||
aggr.push(await deployIsm(ctx, client, v)); | ||
} | ||
|
||
const aggregate = await deployContract(ctx, client, "hpl_ism_aggregate", { | ||
owner: ism.owner === "<signer>" ? client.signer : ism.owner, | ||
isms: aggr.map((v) => v.address), | ||
}); | ||
|
||
return { ...aggregate, isms: aggr }; | ||
|
||
// deploy routing ism | ||
case "routing": | ||
return deployRoutingIsm(ctx, client, ism); | ||
|
||
default: | ||
throw new Error("invalid ism type"); | ||
} | ||
} |