-
Notifications
You must be signed in to change notification settings - Fork 0
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
afc2aaa
commit 76cfb02
Showing
10 changed files
with
435 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,57 @@ | ||
<script lang="ts"> | ||
import { ethers } from "ethers"; | ||
import { signer, mainOrder, creatorSubOrder, autonomousSwap, generalState, partnerState } from "../lib/stores.js"; | ||
import { PartnerState } from "../lib/enums.js"; | ||
import { signer, mainOrder, creatorSubOrder, autonomousSwap, generalState, creatorState, partnerState } from "../lib/stores.js"; | ||
import { CreatorState, PartnerState } from "../lib/enums.js"; | ||
import CreationStep from "./partner/CreationStep.svelte"; | ||
import SwapSection from "./SwapSection.svelte"; | ||
import WaitingJoin from "./partner/WaitingJoin.svelte"; | ||
import AllowanceStep from "./partner/AllowanceStep.svelte"; | ||
import Button from "./base/Button.svelte"; | ||
import FinalStep from "./partner/FinalStep.svelte"; | ||
</script> | ||
|
||
<div> | ||
<h1>PARTNER: {$mainOrder.partner}</h1> | ||
{#if !$mainOrder.isCreator} | ||
{#if $partnerState == PartnerState.WaitingFirstConfirmation} | ||
<CreationStep/> | ||
{:else if $partnerState == PartnerState.AllowingAutonomousSwap} | ||
<p>teste2</p> | ||
{:else if $partnerState == PartnerState.WaitingCreatorAllowance} | ||
<p>teste3</p> | ||
{:else if $partnerState == PartnerState.WaitingCreatorsFunding} | ||
<p>teste4</p> | ||
{:else if $partnerState == PartnerState.SendingTokens} | ||
<p>teste5</p> | ||
{:else if $partnerState == PartnerState.Completed} | ||
<p>teste6</p> | ||
{/if} | ||
|
||
<SwapSection> | ||
<!-- {#if $mainOrder.finalTransaction == null} --> | ||
{#if !($partnerState == PartnerState.Completed && $creatorState == CreatorState.Completed)} | ||
<div> | ||
<h1 class="pb-5"><strong>Creator:</strong> {$mainOrder.creator}</h1> | ||
<hr class="mb-5 h-0.5 bg-black"> | ||
{#if $creatorState == CreatorState.WaitingForPartnerJoin} | ||
<CreationStep isCreator={true}/> | ||
{:else if $creatorState == CreatorState.AllowingAutonomousSwap || $creatorState == CreatorState.WaitingPartnerAllowance} | ||
<AllowanceStep isCreator={true}/> | ||
{:else if $creatorState == CreatorState.SendingTokens} | ||
<FinalStep isCreator={true} /> | ||
{:else if $creatorState == CreatorState.WaitingPartnersTransfer} | ||
<p>Finished! Now, just await for the partner.</p> | ||
{:else if $creatorState == CreatorState.Completed} | ||
<p>Finished!</p> | ||
{/if} | ||
</div> | ||
|
||
<div> | ||
<h1 class="pb-5"><strong>Partner:</strong> {($mainOrder.partner != '0x0000000000000000000000000000000000000000' && $mainOrder.partner) ? $mainOrder.partner : 'waiting...'}</h1> | ||
<hr class="mb-5 h-0.5 bg-black"> | ||
{#if $partnerState == null} | ||
<WaitingJoin>partner.</WaitingJoin> | ||
{:else if $partnerState == PartnerState.WaitingFirstConfirmation} | ||
<CreationStep on:click={() => {$creatorState = CreatorState.AllowingAutonomousSwap; $partnerState = PartnerState.AllowingAutonomousSwap}}/> | ||
{:else if $partnerState == PartnerState.AllowingAutonomousSwap || $partnerState == PartnerState.WaitingCreatorAllowance} | ||
<AllowanceStep /> | ||
{#if $creatorState == CreatorState.WaitingPartnerAllowance && $partnerState == PartnerState.WaitingCreatorAllowance} | ||
<Button isStep={true} on:click={() => {$creatorState = CreatorState.SendingTokens; $partnerState = PartnerState.WaitingCreatorsFunding}}>Next Step</Button> | ||
{/if} | ||
{:else if $partnerState == PartnerState.WaitingCreatorsFunding} | ||
<FinalStep /> | ||
{:else if $partnerState == PartnerState.Completed} | ||
<p>Finished!</p> | ||
{/if} | ||
</div> | ||
|
||
{:else} | ||
<p>WAITING</p> | ||
<div class="col-span-2 "> | ||
<h1 class="text-6xl">Order Completed!!!</h1> | ||
</div> | ||
{/if} | ||
</div> | ||
</SwapSection> |
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,30 @@ | ||
<script lang="ts"> | ||
import Button from "../base/Button.svelte"; | ||
import { autonomousSwap, mainOrder, partnerSubOrder, creatorState, partnerState, creatorSubOrder, signer } from "../../lib/stores.js"; | ||
import { onDestroy } from "svelte"; | ||
import { ContractTransactionResponse } from "ethers"; | ||
let cancelled = false | ||
let _autonomousSwap: AutonomousSwapContract; | ||
const unsubscribe = autonomousSwap.subscribe((value) => { | ||
_autonomousSwap = value; | ||
}) | ||
onDestroy(unsubscribe); | ||
async function cancelOrder(){ | ||
const transactionResponse: ContractTransactionResponse = await _autonomousSwap.cancelOrder($mainOrder.orderId); | ||
const transactionReceipt = await transactionResponse.wait(); | ||
if (transactionReceipt.status == 1){ | ||
cancelled = true; | ||
} | ||
} | ||
</script> | ||
|
||
<div class="absolute -top-[150%]"> | ||
<Button on:click={cancelOrder}> | ||
{cancelled ? 'Cancelled!!' : 'Cancel'} | ||
</Button> | ||
</div> |
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,152 @@ | ||
<script lang="ts"> | ||
import { CreatorState, PartnerState } from "../../lib/enums.js"; | ||
import { autonomousSwap, mainOrder, partnerSubOrder, creatorState, partnerState, creatorSubOrder, signer } from "../../lib/stores.js"; | ||
import Button from "../base/Button.svelte"; | ||
import { IERC1155, IERC721, IERC20} from '../../../core/typechain-types/index.js'; | ||
import * as IERC20json from '../../assets/IERC20.json'; | ||
import * as IERC721json from '../../assets/IERC721.json'; | ||
import * as IERC1155json from '../../assets/IERC1155.json'; | ||
import { ethers } from "ethers"; | ||
import { onMount } from "svelte"; | ||
import Loader from "../base/Loader.svelte"; | ||
export let isCreator = false; | ||
let creatorAllowance = false; | ||
let partnerAllowance = false; | ||
let tokenTypes = { | ||
ERC20: '0xec20ec20', | ||
ERC721: '0x80ac58cd', | ||
ERC1155: '0xd9b67a26' | ||
}; | ||
let interfaceID; | ||
if (isCreator){ | ||
interfaceID = $creatorSubOrder.interfaceID; | ||
creatorResponse() | ||
} else { | ||
interfaceID = $partnerSubOrder.interfaceID; | ||
partnerResponse() | ||
} | ||
async function creatorResponse(){ | ||
if (creatorAllowance) return; | ||
let response = await isAllowed($creatorSubOrder.token, $mainOrder.creator, interfaceID, $creatorSubOrder.quantity, $creatorSubOrder.tokenId) | ||
console.log(response) | ||
if (response) { | ||
creatorAllowance = true; | ||
$creatorState = CreatorState.WaitingPartnerAllowance; | ||
} | ||
console.log(partnerAllowance) | ||
setTimeout(creatorResponse, 1000); | ||
} | ||
async function partnerResponse(){ | ||
if (partnerAllowance) return; | ||
let response = await isAllowed($partnerSubOrder.token, $mainOrder.partner, interfaceID, $partnerSubOrder.quantity, $partnerSubOrder.tokenId) | ||
console.log(response) | ||
if (response) { | ||
partnerAllowance = true; | ||
$partnerState = PartnerState.WaitingCreatorAllowance; | ||
} | ||
console.log(partnerAllowance) | ||
setTimeout(partnerResponse, 1000); | ||
} | ||
async function isAllowed(tokenAddress, owner, interfaceID, quantity, tokenId):Promise<boolean> { | ||
console.log(tokenAddress, interfaceID, quantity, tokenId) | ||
let contract: IERC20 & IERC721 & IERC1155 & ethers.BaseContract; | ||
let autonomousSwapAddress = await $autonomousSwap.getAddress(); | ||
let result; | ||
if (interfaceID == tokenTypes.ERC20){ | ||
contract = new ethers.Contract(tokenAddress, IERC20json.abi, $signer) as IERC20 | any; | ||
result = await contract.allowance(owner, autonomousSwapAddress); | ||
console.log(result) | ||
if (result >= quantity) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} else | ||
if (interfaceID == tokenTypes.ERC721){ | ||
contract = new ethers.Contract(tokenAddress, IERC721json.abi, $signer) as IERC20 | any; | ||
result = await contract.getApproved(tokenId); | ||
console.log(result) | ||
if (result == autonomousSwapAddress) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} else { | ||
contract = new ethers.Contract(tokenAddress, IERC1155json.abi, $signer) as IERC20 | any; | ||
result = await contract.isApprovedForAll(owner, autonomousSwapAddress); | ||
console.log(result) | ||
if (result) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
function getContract(address, interfaceID,): IERC20 & IERC721 & IERC1155 & ethers.BaseContract { | ||
let contract: IERC20 & IERC721 & IERC1155 & ethers.BaseContract; | ||
if (interfaceID == tokenTypes.ERC20){ | ||
return contract = new ethers.Contract(address, IERC20json.abi, $signer) as IERC20 | any; | ||
} else | ||
if (interfaceID == tokenTypes.ERC721){ | ||
return contract = new ethers.Contract(address, IERC721json.abi, $signer) as IERC721 | any; | ||
} else { | ||
return contract = new ethers.Contract(address, IERC1155json.abi, $signer) as IERC1155 | any; | ||
} | ||
} | ||
async function requestAllowance(tokenAddress){ | ||
let autonomousSwapAddress = await $autonomousSwap.getAddress(); | ||
let transactionResponse; | ||
let contract = getContract(tokenAddress, interfaceID); | ||
if (interfaceID == tokenTypes.ERC20){ | ||
transactionResponse = await contract.approve(autonomousSwapAddress, $creatorSubOrder.quantity); | ||
} else | ||
if (interfaceID == tokenTypes.ERC721){ | ||
transactionResponse = await contract.approve(autonomousSwapAddress, $creatorSubOrder.tokenId); | ||
} else { | ||
transactionResponse = await contract.setApprovalForAll(autonomousSwapAddress, true); | ||
} | ||
const transactionReceipt = await transactionResponse.wait(); | ||
if (transactionReceipt.status == 1){ | ||
creatorAllowance = true; | ||
} | ||
} | ||
$: console.log(creatorAllowance, partnerAllowance) | ||
</script> | ||
|
||
|
||
{#if isCreator} | ||
{#if creatorAllowance} | ||
<p>Allowance approved!</p> | ||
{:else} | ||
Awaiting Allowance ... | ||
<Loader></Loader> | ||
{/if} | ||
|
||
{:else} | ||
{#if partnerAllowance} | ||
<p>Allowance approved!</p> | ||
{:else} | ||
<Button on:click={() => requestAllowance($partnerSubOrder.token)}>Give Allowance</Button> | ||
{/if} | ||
{/if} |
Oops, something went wrong.