-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor to support multichain
- Loading branch information
1 parent
33ba39e
commit 3252b65
Showing
15 changed files
with
1,331 additions
and
1,424 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 |
---|---|---|
@@ -1,41 +1,11 @@ | ||
import { Address, BigInt } from "@graphprotocol/graph-ts"; | ||
|
||
import { | ||
User, | ||
FakeGotchiCardBalance, | ||
} from "../../generated/schema"; | ||
|
||
import { constants } from "@amxx/graphprotocol-utils"; | ||
import { BigInt } from "@graphprotocol/graph-ts"; | ||
|
||
export function replaceURI(uri: string, identifier: BigInt): string { | ||
return uri.replaceAll( | ||
"{id}", | ||
identifier | ||
.toHex() | ||
.slice(2) | ||
.padStart(64, "0") | ||
); | ||
} | ||
|
||
export function fetchFakeGotchiCardBalance( | ||
token: BigInt, | ||
account: User | null, | ||
contract: Address | ||
): FakeGotchiCardBalance { | ||
let id = token.toString() | ||
.concat("/") | ||
.concat(account ? account.id.toString() : "totalSupply"); | ||
let balance = FakeGotchiCardBalance.load(id); | ||
|
||
if (balance == null) { | ||
balance = new FakeGotchiCardBalance(id); | ||
balance.contract = contract; | ||
balance.token = token; | ||
balance.account = account ? account.id : null; | ||
balance.value = constants.BIGDECIMAL_ZERO; | ||
balance.valueExact = constants.BIGINT_ZERO; | ||
balance.save(); | ||
} | ||
|
||
return balance as FakeGotchiCardBalance; | ||
return uri.replaceAll( | ||
"{id}", | ||
identifier | ||
.toHex() | ||
.slice(2) | ||
.padStart(64, "0") | ||
); | ||
} |
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,55 +0,0 @@ | ||
import { | ||
Address, | ||
BigInt, | ||
Bytes, | ||
JSONValue, | ||
TypedMap, | ||
log | ||
} from "@graphprotocol/graph-ts"; | ||
|
||
import { | ||
User, | ||
FakeGotchiNFTToken, | ||
} from "../../generated/schema"; | ||
|
||
import { constants } from "@amxx/graphprotocol-utils"; | ||
|
||
import { IERC721 } from "../../generated/FAKEGotchisNFTDiamond/IERC721"; | ||
import { getOrCreateUser } from "../utils/helpers/diamond"; | ||
|
||
export function fetchFakeGotchiNFTToken( | ||
contract: Address, | ||
identifier: BigInt | ||
): FakeGotchiNFTToken { | ||
let id = contract | ||
.toHex() | ||
.concat("/") | ||
.concat(identifier.toHex()); | ||
let token = FakeGotchiNFTToken.load(id); | ||
|
||
if (token == null) { | ||
token = new FakeGotchiNFTToken(id); | ||
token.contract = contract; | ||
token.identifier = identifier; | ||
token.approval = getOrCreateUser(constants.ADDRESS_ZERO.toHex()).id; | ||
|
||
let erc721 = IERC721.bind(Address.fromBytes(contract)); | ||
let try_tokenURI = erc721.try_tokenURI(identifier); | ||
token.uri = try_tokenURI.reverted ? "" : try_tokenURI.value; | ||
} | ||
|
||
|
||
return token as FakeGotchiNFTToken; | ||
} | ||
|
||
export function getFakeGotchiNFTToken( | ||
contract: Address, | ||
identifier: BigInt | ||
): FakeGotchiNFTToken | null { | ||
let id = contract | ||
.toHex() | ||
.concat("/") | ||
.concat(identifier.toHex()); | ||
let token = FakeGotchiNFTToken.load(id); | ||
return token; | ||
} | ||
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
Oops, something went wrong.