This repository has been archived by the owner on May 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TD1119 Part 2 Add create primary sale workflow to SDK (#414)
* oas gen Signed-off-by: Frank Li <[email protected]> * remove create project func Signed-off-by: Frank Li <[email protected]> * remove create project example Signed-off-by: Frank Li <[email protected]> * add create primary sale workflow Signed-off-by: Frank Li <[email protected]> * update api Signed-off-by: Frank Li <[email protected]> * fix fees missed mapping Signed-off-by: Frank Li <[email protected]> --------- Signed-off-by: Frank Li <[email protected]>
- Loading branch information
1 parent
4e99252
commit f70ed54
Showing
8 changed files
with
180 additions
and
58 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
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
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
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
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
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
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,79 @@ | ||
import { | ||
CreatePrimarySaleBadRequestBody, | ||
CreatePrimarySaleCreatedBody, | ||
CreatePrimarySaleForbiddenBody, | ||
CreatePrimarySaleNotFoundBody, | ||
CreatePrimarySaleUnauthorizedBody, | ||
PrimarySalesApi, | ||
PrimarySalesApiCreatePrimarySaleRequest, | ||
PrimarySalesApiSignableCreatePrimarySaleRequest, | ||
} from '../api'; | ||
import { WalletConnection } from '../types'; | ||
import { signRaw } from '../utils'; | ||
|
||
type CreatePrimarySaleWorkflowParams = WalletConnection & { | ||
request: PrimarySalesApiSignableCreatePrimarySaleRequest; | ||
primarySalesApi: PrimarySalesApi; | ||
}; | ||
|
||
type CreatePrimarySaleResponse = | ||
| CreatePrimarySaleBadRequestBody | ||
| CreatePrimarySaleCreatedBody | ||
| CreatePrimarySaleForbiddenBody | ||
| CreatePrimarySaleUnauthorizedBody | ||
| CreatePrimarySaleNotFoundBody; | ||
|
||
export async function CreatePrimarySaleWorkflow({ | ||
ethSigner, | ||
starkSigner, | ||
request, | ||
primarySalesApi, | ||
}: CreatePrimarySaleWorkflowParams): Promise<CreatePrimarySaleResponse> { | ||
const ethAddress = await ethSigner.getAddress(); | ||
|
||
const signablePrimarySaleResponse = | ||
await primarySalesApi.signableCreatePrimarySale(request); | ||
|
||
const { signable_message: signableMessage, payload_hash: payloadHash } = | ||
signablePrimarySaleResponse.data; | ||
|
||
const ethSignature = await signRaw(signableMessage, ethSigner); | ||
|
||
const starkSignature = await starkSigner.signMessage(payloadHash); | ||
|
||
const resp = signablePrimarySaleResponse.data; | ||
|
||
const primarySaleParams: PrimarySalesApiCreatePrimarySaleRequest = { | ||
body: { | ||
buyer_ether_key: resp.buyer_ether_key, | ||
buyer_stark_key: resp.buyer_stark_key, | ||
buyer_vault_id: resp.buyer_vault_id, | ||
studio_ether_key: resp.studio_ether_key, | ||
studio_data: resp.studio_data, | ||
payment_amount: resp.payment_amount, | ||
payment_asset_id: resp.payment_asset_id, | ||
payment_recipient_ether_key: resp.payment_recipient_ether_key, | ||
payment_recipient_stark_key: resp.payment_recipient_stark_key, | ||
payment_recipient_vault_id: resp.payment_recipient_vault_id, | ||
items_recipient_ether_key: resp.items_recipient_ether_key, | ||
expiration_timestamp: resp.expiration_timestamp, | ||
fees: resp.fees, | ||
nonce: resp.nonce, | ||
stark_signature: starkSignature, | ||
}, | ||
}; | ||
|
||
const createPrimarySaleResp = await primarySalesApi.createPrimarySale( | ||
primarySaleParams, | ||
{ | ||
headers: { | ||
'x-imx-eth-address': ethAddress, | ||
'x-imx-eth-signature': ethSignature, | ||
}, | ||
}, | ||
); | ||
|
||
return { | ||
...createPrimarySaleResp.data, | ||
}; | ||
} |
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