Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class OperatorCategory(Enum):
"https://api.studio.thegraph.com/query/74256/ethereum/version/latest"
),
"subgraph_url_api_key": (
"https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmZEF1exsjDwjDXy1kmN3MbdZKxfkkoTj2MbEPUyhLfEG3"
"https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmUe2Zpp9uZmYRLsgiEJQA87CCna4ZaRGUiQ7cU1f58dVV"
),
"hmt_address": "0xd1ba9BAC957322D6e8c07a160a3A8dA11A0d2867",
"factory_address": "0xD9c75a1Aa4237BB72a41E5E26bd8384f10c1f55a",
Expand All @@ -52,7 +52,7 @@ class OperatorCategory(Enum):
"https://api.studio.thegraph.com/query/74256/sepolia/version/latest"
),
"subgraph_url_api_key": (
"https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmeHhtntEYGdgTqHQTJu5mUXHS8JPt3RiwidLYeeEu6VpP"
"https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmbPBqzyRt3zAtF6BtY52P8wn7Gc3qdjWuKLHdargK8WZp"
),
"hmt_address": "0x792abbcC99c01dbDec49c9fa9A828a186Da45C33",
"factory_address": "0x5987A5558d961ee674efe4A8c8eB7B1b5495D3bf",
Expand All @@ -68,7 +68,7 @@ class OperatorCategory(Enum):
"https://api.studio.thegraph.com/query/74256/bsc/version/latest"
),
"subgraph_url_api_key": (
"hthttps://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmWsXVhdFuZZcXDjXrv1QLSBYcjNShazFQmNUdpAErjQqD"
"hthttps://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmYP2yo1NGNWGf585uwyRifERv6ZJbJqse3q9Xv1izrR5D"
),
"hmt_address": "0x711Fd6ab6d65A98904522d4e3586F492B989c527",
"factory_address": "0x92FD968AcBd521c232f5fB8c33b342923cC72714",
Expand All @@ -84,7 +84,7 @@ class OperatorCategory(Enum):
"https://api.studio.thegraph.com/query/74256/bsc-testnet/version/latest"
),
"subgraph_url_api_key": (
"https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmPv7asd21BA5LZJxjDPfoL5ZJkEGMvahrdMqgNQnP5sxn"
"https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmekNGfmcY6trj3m471kQLWg3YSKM7UaRJ3Ef3MBxWfu6o"
),
"hmt_address": "0xE3D74BBFa45B4bCa69FF28891fBE392f4B4d4e4d",
"factory_address": "0x2bfA592DBDaF434DDcbb893B1916120d181DAD18",
Expand All @@ -102,7 +102,7 @@ class OperatorCategory(Enum):
"https://api.studio.thegraph.com/query/74256/polygon/version/latest"
),
"subgraph_url_api_key": (
"https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmZSsJn5TERyEfRrrbY926hLHD321ijoMynrxWxc3boRa6"
"https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmTv69h7rW9SMSfLJN4WHzMA4qYttX2GzzfM5Drey4mCRp"
),
"hmt_address": "0xc748B2A084F8eFc47E086ccdDD9b7e67aEb571BF",
"factory_address": "0xBDBfD2cC708199C5640C6ECdf3B0F4A4C67AdfcB",
Expand All @@ -120,7 +120,7 @@ class OperatorCategory(Enum):
"https://api.studio.thegraph.com/query/74256/amoy/version/latest"
),
"subgraph_url_api_key": (
"https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmYWc4ciJbAvTvcjoBzRSTWZrf1xD8WPRqEk3xtJZUKZqY"
"https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmUe97VzETuP1zQ6oD2trtu9RvSxpRSUrv4uhF1y5dzQDN"
),
"hmt_address": "0x792abbcC99c01dbDec49c9fa9A828a186Da45C33",
"factory_address": "0xAFf5a986A530ff839d49325A5dF69F96627E8D29",
Expand Down
12 changes: 6 additions & 6 deletions packages/sdk/typescript/human-protocol-sdk/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const NETWORKS: {
subgraphUrl:
'https://api.studio.thegraph.com/query/74256/ethereum/version/latest',
subgraphUrlApiKey:
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmZEF1exsjDwjDXy1kmN3MbdZKxfkkoTj2MbEPUyhLfEG3',
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmUe2Zpp9uZmYRLsgiEJQA87CCna4ZaRGUiQ7cU1f58dVV',
oldSubgraphUrl: '',
oldFactoryAddress: '',
},
Expand All @@ -51,7 +51,7 @@ export const NETWORKS: {
subgraphUrl:
'https://api.studio.thegraph.com/query/74256/sepolia/version/latest',
subgraphUrlApiKey:
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmeHhtntEYGdgTqHQTJu5mUXHS8JPt3RiwidLYeeEu6VpP',
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmbPBqzyRt3zAtF6BtY52P8wn7Gc3qdjWuKLHdargK8WZp',
oldSubgraphUrl: '',
oldFactoryAddress: '',
},
Expand All @@ -66,7 +66,7 @@ export const NETWORKS: {
subgraphUrl:
'https://api.studio.thegraph.com/query/74256/bsc/version/latest',
subgraphUrlApiKey:
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmWsXVhdFuZZcXDjXrv1QLSBYcjNShazFQmNUdpAErjQqD',
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmYP2yo1NGNWGf585uwyRifERv6ZJbJqse3q9Xv1izrR5D',
oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc',
oldFactoryAddress: '0xc88bC422cAAb2ac8812de03176402dbcA09533f4',
},
Expand All @@ -81,7 +81,7 @@ export const NETWORKS: {
subgraphUrl:
'https://api.studio.thegraph.com/query/74256/bsc-testnet/version/latest',
subgraphUrlApiKey:
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmPv7asd21BA5LZJxjDPfoL5ZJkEGMvahrdMqgNQnP5sxn',
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmekNGfmcY6trj3m471kQLWg3YSKM7UaRJ3Ef3MBxWfu6o',
oldSubgraphUrl:
'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest',
oldFactoryAddress: '0xaae6a2646c1f88763e62e0cd08ad050ea66ac46f',
Expand All @@ -97,7 +97,7 @@ export const NETWORKS: {
subgraphUrl:
'https://api.studio.thegraph.com/query/74256/polygon/version/latest',
subgraphUrlApiKey:
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmZSsJn5TERyEfRrrbY926hLHD321ijoMynrxWxc3boRa6',
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmTv69h7rW9SMSfLJN4WHzMA4qYttX2GzzfM5Drey4mCRp',
oldSubgraphUrl:
'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon',
oldFactoryAddress: '0x45eBc3eAE6DA485097054ae10BA1A0f8e8c7f794',
Expand All @@ -113,7 +113,7 @@ export const NETWORKS: {
subgraphUrl:
'https://api.studio.thegraph.com/query/74256/amoy/version/latest',
subgraphUrlApiKey:
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmYWc4ciJbAvTvcjoBzRSTWZrf1xD8WPRqEk3xtJZUKZqY',
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmUe97VzETuP1zQ6oD2trtu9RvSxpRSUrv4uhF1y5dzQDN',
oldSubgraphUrl: '',
oldFactoryAddress: '',
},
Expand Down
26 changes: 21 additions & 5 deletions packages/sdk/typescript/subgraph/src/mapping/EscrowTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,18 +639,34 @@ export function handleCompleted(event: Completed): void {
// Update escrow entity
const escrowEntity = Escrow.load(dataSource.address());
if (escrowEntity) {
escrowEntity.status = 'Complete';
escrowEntity.save();
eventEntity.launcher = escrowEntity.launcher;

createTransaction(
const transaction = createTransaction(
event,
'complete',
event.transaction.from,
Address.fromBytes(escrowEntity.address),
null,
Address.fromBytes(escrowEntity.address)
);
if (
escrowEntity.balance &&
escrowEntity.balance.gt(ZERO_BI) &&
escrowEntity.token != HMT_ADDRESS
) {
const internalTransaction = new InternalTransaction(toEventId(event));
internalTransaction.from = escrowEntity.address;
internalTransaction.to = escrowEntity.launcher;
internalTransaction.value = escrowEntity.balance;
internalTransaction.transaction = transaction.id;
internalTransaction.method = 'transfer';
internalTransaction.escrow = escrowEntity.address;
internalTransaction.token = escrowEntity.token;
internalTransaction.save();

escrowEntity.balance = ZERO_BI;
}
escrowEntity.status = 'Complete';
escrowEntity.save();
eventEntity.launcher = escrowEntity.launcher;
}
eventEntity.save();
}
Expand Down
151 changes: 147 additions & 4 deletions packages/sdk/typescript/subgraph/tests/escrow/escrow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('Escrow', () => {

const escrow = new Escrow(escrowAddress);
escrow.address = escrowAddress;
escrow.token = Address.zero();
escrow.token = tokenAddress;
escrow.factoryAddress = Address.zero();
escrow.launcher = launcherAddress;
escrow.canceler = launcherAddress;
Expand Down Expand Up @@ -1318,7 +1318,106 @@ describe('Escrow', () => {
});

test('Should properly handle Completed event', () => {
const newCompleted = createCompletedEvent(operatorAddress);
const newCompleted = createCompletedEvent(
operatorAddress,
BigInt.fromI32(12)
);

handleCompleted(newCompleted);

const id = toEventId(newCompleted).toHex();

// EscrowStatusEvent
assert.fieldEquals(
'EscrowStatusEvent',
id,
'block',
newCompleted.block.number.toString()
);
assert.fieldEquals(
'EscrowStatusEvent',
id,
'timestamp',
newCompleted.block.timestamp.toString()
);
assert.fieldEquals(
'EscrowStatusEvent',
id,
'txHash',
newCompleted.transaction.hash.toHex()
);
assert.fieldEquals(
'EscrowStatusEvent',
id,
'escrowAddress',
escrowAddressString
);
assert.fieldEquals(
'EscrowStatusEvent',
id,
'sender',
operatorAddressString
);
assert.fieldEquals('EscrowStatusEvent', id, 'status', 'Complete');
assert.fieldEquals(
'EscrowStatusEvent',
id,
'launcher',
launcherAddressString
);

// Escrow
assert.fieldEquals('Escrow', escrowAddress.toHex(), 'status', 'Complete');
assert.fieldEquals(
'Transaction',
newCompleted.transaction.hash.toHex(),
'txHash',
newCompleted.transaction.hash.toHex()
);
assert.fieldEquals(
'Transaction',
newCompleted.transaction.hash.toHex(),
'method',
'complete'
);
assert.fieldEquals(
'Transaction',
newCompleted.transaction.hash.toHex(),
'block',
newCompleted.block.number.toString()
);
assert.fieldEquals(
'Transaction',
newCompleted.transaction.hash.toHex(),
'from',
newCompleted.transaction.from.toHex()
);
assert.fieldEquals(
'Transaction',
newCompleted.transaction.hash.toHex(),
'to',
escrowAddressString
);

// InternalTransaction
const internalTxId = toEventId(newCompleted).toHex();
assert.notInStore('InternalTransaction', internalTxId);

// Escrow balance should be 0 after completion
assert.fieldEquals('Escrow', escrowAddress.toHex(), 'balance', '0');
});

test('Should properly handle Completed event and create InternalTransaction if escrow has balance', () => {
const escrow = Escrow.load(escrowAddress);
if (escrow) {
escrow.balance = BigInt.fromI32(1234);
escrow.save();
}

const newCompleted = createCompletedEvent(
operatorAddress,
BigInt.fromI32(13)
);

handleCompleted(newCompleted);

Expand Down Expand Up @@ -1395,6 +1494,44 @@ describe('Escrow', () => {
'to',
escrowAddressString
);

// InternalTransaction
const internalTxId = toEventId(newCompleted).toHex();

assert.fieldEquals(
'InternalTransaction',
internalTxId,
'from',
escrowAddressString
);
assert.fieldEquals(
'InternalTransaction',
internalTxId,
'to',
launcherAddressString
);
assert.fieldEquals('InternalTransaction', internalTxId, 'value', '1234');
assert.fieldEquals(
'InternalTransaction',
internalTxId,
'method',
'transfer'
);
assert.fieldEquals(
'InternalTransaction',
internalTxId,
'escrow',
escrowAddressString
);
assert.fieldEquals(
'InternalTransaction',
internalTxId,
'transaction',
newCompleted.transaction.hash.toHex()
);

// Escrow balance should be 0 after completion
assert.fieldEquals('Escrow', escrowAddress.toHex(), 'balance', '0');
});

test('Should properly handle Withdraw event', () => {
Expand Down Expand Up @@ -1680,8 +1817,14 @@ describe('Escrow', () => {
});

test('Should properly calculate completed event in statstics', () => {
const newCompleted1 = createCompletedEvent(operatorAddress);
const newCompleted2 = createCompletedEvent(operatorAddress);
const newCompleted1 = createCompletedEvent(
operatorAddress,
BigInt.fromI32(12)
);
const newCompleted2 = createCompletedEvent(
operatorAddress,
BigInt.fromI32(13)
);

handleCompleted(newCompleted1);
handleCompleted(newCompleted2);
Expand Down
10 changes: 9 additions & 1 deletion packages/sdk/typescript/subgraph/tests/escrow/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,16 @@ export function createCancelledEvent(sender: Address): Cancelled {
return newCancelledEvent;
}

export function createCompletedEvent(sender: Address): Completed {
export function createCompletedEvent(
sender: Address,
timestamp: BigInt
): Completed {
const newCompletedEvent = changetype<Completed>(newMockEvent());
newCompletedEvent.transaction.hash = generateUniqueHash(
sender.toString(),
timestamp,
newCompletedEvent.transaction.nonce
);

newCompletedEvent.transaction.from = sender;

Expand Down
Loading