Skip to content

Commit

Permalink
feat(sdk-deployer): add sdk & deployer update to support fully onchai…
Browse files Browse the repository at this point in the history
…n protocol
  • Loading branch information
kwiss committed Sep 10, 2024
1 parent f083deb commit 5a165fe
Show file tree
Hide file tree
Showing 20 changed files with 59 additions and 287 deletions.
27 changes: 2 additions & 25 deletions contracts/ark_starknet/src/executor.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,14 @@ impl OrderV1IntoOrderInfo of Into<OrderV1, OrderInfo> {
}
}
}
//! Executor contract on Starknet for arkchain.

//! Executor contract on Starknet
//!
//! This contract is responsible of executing the orders
//! and move the assets accordingly.
//! Once done, an event is emitted to confirm at the arkchain
//! that the order was executed correctly.
//!
//! In order to communicate with the Arkchain, this contract
//! uses the `appchain_messaging` contract dispatcher to send
//! messages.

#[starknet::contract]
mod executor {
Expand All @@ -69,9 +67,6 @@ mod executor {
use ark_oz::erc2981::{FeesRatio, FeesRatioDefault, FeesImpl};
use ark_oz::erc2981::{IERC2981Dispatcher, IERC2981DispatcherTrait};

use ark_starknet::appchain_messaging::{
IAppchainMessagingDispatcher, IAppchainMessagingDispatcherTrait,
};
use ark_starknet::interfaces::FeesAmount;

use ark_starknet::interfaces::{IExecutor, IUpgradable, IMaintenance};
Expand Down Expand Up @@ -103,7 +98,6 @@ mod executor {
admin_address: ContractAddress,
arkchain_orderbook_address: ContractAddress,
eth_contract_address: ContractAddress,
messaging_address: ContractAddress,
chain_id: felt252,
broker_fees: Map<ContractAddress, FeesRatio>,
ark_fees: FeesRatio,
Expand Down Expand Up @@ -168,12 +162,10 @@ mod executor {
ref self: ContractState,
admin_address: ContractAddress,
eth_contract_address: ContractAddress,
messaging_address: ContractAddress,
chain_id: felt252
) {
self.admin_address.write(admin_address);
self.eth_contract_address.write(eth_contract_address);
self.messaging_address.write(messaging_address);
self.chain_id.write(chain_id);
self.ark_fees.write(Default::default());
self.default_receiver.write(admin_address);
Expand Down Expand Up @@ -271,10 +263,6 @@ mod executor {
}
}

fn get_messaging_address(self: @ContractState) -> ContractAddress {
self.messaging_address.read()
}

fn get_orderbook_address(self: @ContractState) -> ContractAddress {
self.arkchain_orderbook_address.read()
}
Expand All @@ -287,12 +275,6 @@ mod executor {
self.arkchain_orderbook_address.write(orderbook_address);
}

fn update_messaging_address(ref self: ContractState, msger_address: ContractAddress) {
_ensure_admin(@self);

self.messaging_address.write(msger_address);
}

fn update_eth_address(ref self: ContractState, eth_address: ContractAddress) {
_ensure_admin(@self);

Expand Down Expand Up @@ -598,11 +580,6 @@ mod executor {
}

fn _execute_order(ref self: ContractState, execution_info: ExecutionInfo) {
// assert(
// starknet::get_caller_address() == self.messaging_address.read(),
// 'Invalid msg sender'
// );

// Check if execution_info.currency_contract_address is whitelisted
_ensure_is_not_in_maintenance(@self);
assert(
Expand Down
2 changes: 0 additions & 2 deletions contracts/ark_starknet/src/interfaces.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ trait IExecutor<T> {
fn update_admin_address(ref self: T, admin_address: ContractAddress);
fn update_orderbook_address(ref self: T, orderbook_address: ContractAddress);
fn update_eth_address(ref self: T, eth_address: ContractAddress);
fn update_messaging_address(ref self: T, msger_address: ContractAddress);
fn get_messaging_address(self: @T) -> ContractAddress;
fn get_orderbook_address(self: @T) -> ContractAddress;
fn update_arkchain_orderbook_address(ref self: T, orderbook_address: ContractAddress);
fn set_broker_fees(ref self: T, fees_ratio: FeesRatio);
Expand Down
7 changes: 1 addition & 6 deletions examples/core/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ export const starknetExecutorContract = verifyContractAddress(
contracts.executor,
"Executor"
);
export const arkchainOrderbookContract = verifyContractAddress(
contracts.orderbook,
"Orderbook"
);
export const starknetCurrencyContract = verifyContractAddress(
isDev && isDevContracts(contracts) ? contracts.eth : starknetEthContract,
"Currency"
Expand All @@ -101,6 +97,5 @@ export const config = createConfig({
starknetNetwork: network,
starknetExecutorContract,
starknetCurrencyContract,
arkchainNetwork: network,
arkchainOrderbookContract
arkchainNetwork: network
});
33 changes: 0 additions & 33 deletions examples/core/utils/whitelistBroker.ts

This file was deleted.

6 changes: 4 additions & 2 deletions packages/core/src/actions/order/createAuction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ const createAuction = async (
) => {
const { starknetAccount, order: baseOrder, approveInfo } = parameters;
const currentDate = new Date();
currentDate.setDate(currentDate.getDate() + 30);
currentDate.setDate(currentDate.getDate());
const startDate = baseOrder.startDate || Math.floor(Date.now() / 1000);
const endDate = baseOrder.endDate || Math.floor(currentDate.getTime() / 1000);
const endDate =
baseOrder.endDate ||
Math.floor(currentDate.getTime() / 1000) + 60 * 60 * 24 * 7;
const chainId = await config.starknetProvider.getChainId();

if (startDate < Math.floor(Date.now() / 1000)) {
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/actions/order/createListing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ const createListing = async (
) => {
const { starknetAccount, order: baseOrder, approveInfo } = parameters;
const currentDate = new Date();
currentDate.setDate(currentDate.getDate() + 30);
currentDate.setDate(currentDate.getDate());
const startDate = baseOrder.startDate || Math.floor(Date.now() / 1000);
const endDate = baseOrder.endDate || Math.floor(currentDate.getTime() / 1000);
const endDate =
baseOrder.endDate ||
Math.floor(currentDate.getTime() / 1000) + 60 * 60 * 24 * 7;
const chainId = await config.starknetProvider.getChainId();

const order: OrderV1 = {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/actions/order/createOffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ const createOffer = async (
) => {
const { starknetAccount, offer: baseOrder, approveInfo } = parameters;
const currentDate = new Date();
currentDate.setDate(currentDate.getDate() + 30);
currentDate.setDate(currentDate.getDate());
const startDate = baseOrder.startDate || Math.floor(Date.now() / 1000);
const endDate = baseOrder.endDate || Math.floor(currentDate.getTime() / 1000);
const currencyAddress =
baseOrder.currencyAddress || config.starknetCurrencyContract;
const endDate =
baseOrder.endDate || Math.floor(currentDate.getTime() / 1000) + 30;

if (currencyAddress !== approveInfo.currencyAddress) {
throw new Error("Invalid currency address, offer and approveInfo mismatch");
}

const chainId = await config.starknetProvider.getChainId();
const currentAllowance = await getAllowance(
config,
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/actions/read/getOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ interface GetOrderParameters {

const getOrder = async (config: Config, parameters: GetOrderParameters) => {
const { orderHash } = parameters;
const { abi: orderbookAbi } = await config.arkProvider.getClassAt(
config.arkchainOrderbookContract
const { abi: orderbookAbi } = await config.starknetProvider.getClassAt(
config.starknetExecutorContract
);
if (orderbookAbi === undefined) {
throw new Error("no abi.");
}

const orderbookContract = new Contract(
orderbookAbi,
config.arkchainOrderbookContract,
config.arkProvider
config.starknetExecutorContract,
config.starknetProvider
);

const order_hash_calldata = CallData.compile({
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/actions/read/getOrderHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ const getOrderHash = async (

const tokenHashMessage = starknet.poseidonHashMany(tokenHashBigIntArray);

const { abi: orderbookAbi } = await config.arkProvider.getClassAt(
config.arkchainOrderbookContract
const { abi: executorAbi } = await config.starknetProvider.getClassAt(
config.starknetExecutorContract
);
if (orderbookAbi === undefined) {
if (executorAbi === undefined) {
throw new Error("no abi.");
}

const orderbookContract = new Contract(
orderbookAbi,
config.arkchainOrderbookContract,
config.arkProvider
executorAbi,
config.starknetExecutorContract,
config.starknetProvider
);

const order_hash_calldata = CallData.compile({
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/actions/read/getOrderSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ const getOrderSigner = async (
parameters: GetOrderSignerParameters
) => {
const { orderHash } = parameters;
const { abi: orderbookAbi } = await config.arkProvider.getClassAt(
config.arkchainOrderbookContract
const { abi: executorAbi } = await config.starknetProvider.getClassAt(
config.starknetExecutorContract
);
if (orderbookAbi === undefined) {
if (executorAbi === undefined) {
throw new Error("no abi.");
}

const orderbookContract = new Contract(
orderbookAbi,
config.arkchainOrderbookContract,
config.arkProvider
executorAbi,
config.starknetExecutorContract,
config.starknetProvider
);

const order_hash_calldata = CallData.compile({
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/actions/read/getOrderStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ const getOrderStatus = async (
parameters: GetOrderStatusParameters
) => {
const { orderHash } = parameters;
const { abi: orderbookAbi } = await config.arkProvider.getClassAt(
config.arkchainOrderbookContract
const { abi: executorAbi } = await config.starknetProvider.getClassAt(
config.starknetExecutorContract
);
if (orderbookAbi === undefined) {
if (executorAbi === undefined) {
throw new Error("no abi.");
}

const orderbookContract = new Contract(
orderbookAbi,
config.arkchainOrderbookContract,
config.arkProvider
executorAbi,
config.starknetExecutorContract,
config.starknetProvider
);

const order_hash_calldata = CallData.compile({
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/actions/read/getOrderType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ const getOrderType = async (
parameters: GetOrderTypeParameters
) => {
const { orderHash } = parameters;
const { abi: orderbookAbi } = await config.arkProvider.getClassAt(
config.arkchainOrderbookContract
const { abi: executorAbi } = await config.starknetProvider.getClassAt(
config.starknetExecutorContract
);
if (orderbookAbi === undefined) {
if (executorAbi === undefined) {
throw new Error("no abi.");
}

const orderbookContract = new Contract(
orderbookAbi,
config.arkchainOrderbookContract,
config.arkProvider
executorAbi,
config.starknetExecutorContract,
config.starknetProvider
);

const order_hash_calldata = CallData.compile({
Expand Down
14 changes: 6 additions & 8 deletions packages/core/src/contracts.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// This file is auto-generated. Do not edit directly.

export const SEPOLIA_CONTRACTS = {
messaging:
"0x74f13f1dffb5ad3c051d535ba03514e653b6dcac68e30b2db66a0aa0217c815",
executor: "0xb86ab357c15c12fb78f9b0a19fa974c730fcbab96f17881827dde871665f0b",
orderbook: "0x795b605fa3144afd6f11a4499f71b9cf373bcba3f1b2835d51f65ab59392261"
"messaging": "0x74f13f1dffb5ad3c051d535ba03514e653b6dcac68e30b2db66a0aa0217c815",
"executor": "0xb86ab357c15c12fb78f9b0a19fa974c730fcbab96f17881827dde871665f0b",
"orderbook": "0x795b605fa3144afd6f11a4499f71b9cf373bcba3f1b2835d51f65ab59392261"
};
export const MAINNET_CONTRACTS = {
messaging:
"0x57d45cc46de463f7ae63b74ce9b6b6b496a1178b02e7ad04d7c307caa698b7b",
executor: "0x7b42945bc47001db92fe1b9739d753925263f2f1036c2ae1f87536c916ee6a",
orderbook: "0x5add3084bb8664eb2a641cf26a28f60588c3ccd63af0632aafefcbb2332c345"
"messaging": "0x57d45cc46de463f7ae63b74ce9b6b6b496a1178b02e7ad04d7c307caa698b7b",
"executor": "0x7b42945bc47001db92fe1b9739d753925263f2f1036c2ae1f87536c916ee6a",
"orderbook": "0x5add3084bb8664eb2a641cf26a28f60588c3ccd63af0632aafefcbb2332c345"
};
Loading

0 comments on commit 5a165fe

Please sign in to comment.