Skip to content

Commit

Permalink
Feat/accepted tokens (#1067)
Browse files Browse the repository at this point in the history
* feat(tokens): surface accepted tokens

* fix(tokens): acceptedTokens test and fix

* chore(address): update trader address graph

* fix(import): add bigint to import

* fix(log): add logging to trader mapping
  • Loading branch information
bitbeckers authored Sep 6, 2023
1 parent e95571c commit cf9da0a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion graph/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,13 @@ export function getOrCreateToken(token: Address): Token {

if (_token == null) {
_token = new Token(_tokenID);
//TODO get token name
log.debug("Created Token: {}", [_tokenID]);
_token.name = "Native";
_token.save();
}

log.debug("Returning Token: {}", [_tokenID]);

return _token;
}

Expand All @@ -119,6 +121,8 @@ export function getOrCreateAcceptedToken(

if (acceptedToken == null) {
acceptedToken = new AcceptedToken(_acceptedTokenID);
log.debug("Created acceptedToken: {}", [_acceptedTokenID]);

acceptedToken.token = getOrCreateToken(token).id;
acceptedToken.minimumAmountPerUnit = minimumAmountPerUnit;
acceptedToken.accepted = true;
Expand Down Expand Up @@ -146,6 +150,8 @@ export function getOrCreateOffer(
if (offer == null) {
const offerOnChain = _traderContract.getOffer(offerID);
offer = new Offer(_offerID);
log.debug("Created offer: {}", [_offerID]);

offer.fractionID = _fractionID;
offer.unitsAvailable = offerOnChain.unitsAvailable;
offer.minUnitsPerTrade = offerOnChain.minUnitsPerTrade;
Expand All @@ -161,12 +167,18 @@ export function getOrCreateOffer(
_acceptedToken.minimumAmountPerUnit,
);
offer.acceptedTokens.push(parsedToken.id.toString());
log.debug("Added accepted token to offer {} at place {}", [
_offerID,
_acceptedToken.length.toString(),
]);
}

log.debug("Created offerID: {}", [_offerID]);
offer.save();
}

log.debug("Returning offer: {}", [_offerID]);

return offer;
}

Expand Down

0 comments on commit cf9da0a

Please sign in to comment.