Skip to content

Commit

Permalink
split backing and issuing
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 committed Mar 28, 2024
1 parent 8f6e574 commit cd9e7ac
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 1,147 deletions.
5 changes: 4 additions & 1 deletion apollo/.env.prod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ SCROLL_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/59403/lnv3-scroll/v1.
DARWINIA_LNV3_ENDPOINT=https://thegraph-g1.darwinia.network/helix/subgraphs/name/lnv3/darwinia
BLAST_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/59403/lnv3-blast/v1.0.0

XTOKEN_DARWINIA=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/darwinia
XTOKEN_DARWINIA_CRAB_BACKING=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/darwinia-crab-backing
XTOKEN_DARWINIA_CRAB_ISSUING=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/darwinia-crab-issuing
XTOKEN_CRAB_DARWINIA_BACKING=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/crab-darwinia-backing
XTOKEN_CRAB_DARWINIA_ISSUING=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/crab-darwinia-issuing
XTOKEN_CRAB=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/crab
XTOKEN_DISPATCH_DARWINIA=https://thegraph.darwinia.network/helix/subgraphs/name/xtokendispatch/darwinia
XTOKEN_DISPATCH_CRAB=https://thegraph.darwinia.network/helix/subgraphs/name/xtokendispatch/crab
Expand Down
4 changes: 2 additions & 2 deletions apollo/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ZKSYNC_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/61328/lnv3-zksepolia/
BERA_LNV3_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnv3/bera
TAIKO_LNV3_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnv3/taiko

XTOKEN_DARWINIA = https://thegraph-g2.darwinia.network/helix/subgraphs/name/xtokentransfer/pangolin
XTOKEN_ETHEREUM = https://api.studio.thegraph.com/query/61328/xtoken-sepolia/v1.1.8
XTOKEN_DARWINIA_ETHEREUM_BACKING = https://thegraph-g2.darwinia.network/helix/subgraphs/name/xtokentransfer/pangolin
XTOKEN_DARWINIA_ETHEREUM_ISSUING = https://api.studio.thegraph.com/query/61328/xtoken-sepolia/v1.1.8
XTOKEN_DISPATCH_DARWINIA = https://thegraph-g2.darwinia.network/helix/subgraphs/name/xtokendispatch/pangolin
XTOKEN_DISPATCH_ETHEREUM = https://api.studio.thegraph.com/query/61328/xtoken-dispatch-sepolia/v1.1.4
67 changes: 49 additions & 18 deletions apollo/src/xtoken/transfer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import { AddressTokenMap } from '../base/AddressToken';

@Injectable()
export class TransferService extends BaseTransferServiceT2 {
private readonly darwainiaUrl = this.configService.get<string>('XTOKEN_DARWINIA');
private readonly crabUrl = this.configService.get<string>('XTOKEN_CRAB');
private readonly ethereumUrl = this.configService.get<string>('XTOKEN_ETHEREUM');
private readonly darwainiaCrabBackingUrl = this.configService.get<string>('XTOKEN_DARWINIA_CRAB_BACKING');
private readonly darwainiaCrabIssuingUrl = this.configService.get<string>('XTOKEN_DARWINIA_CRAB_ISSUING');
private readonly crabDarwiniaBackingUrl = this.configService.get<string>('XTOKEN_CRAB_DARWINIA_BACKING');
private readonly crabDarwiniaIssuingUrl = this.configService.get<string>('XTOKEN_CRAB_DARWINIA_ISSUING');

private readonly darwiniaEthereumBackingUrl = this.configService.get<string>('XTOKEN_DARWINIA_ETHEREUM_BACKING');
private readonly darwiniaEthereumIssuingUrl = this.configService.get<string>('XTOKEN_DARWINIA_ETHEREUM_ISSUING')
private readonly darwiniaDispatchSubgraph = this.configService.get<string>('XTOKEN_DISPATCH_DARWINIA');
private readonly crabDispatchSubgraph = this.configService.get<string>('XTOKEN_DISPATCH_CRAB');
private readonly ethereumDispatchSubgraph = this.configService.get<string>('XTOKEN_DISPATCH_ETHEREUM');
Expand All @@ -16,8 +20,8 @@ export class TransferService extends BaseTransferServiceT2 {
{
chainId: 46,
chain: 'darwinia-dvm',
url: this.darwainiaUrl,
bridge: 'xtokenbridge',
url: this.darwainiaCrabBackingUrl,
bridge: 'xtoken-darwinia-crab',
symbols: [
{
key: 'RING',
Expand All @@ -26,14 +30,6 @@ export class TransferService extends BaseTransferServiceT2 {
outerAddress: '0x0000000000000000000000000000000000000000',
protocolFee: 0,
decimals: 18,
},
{
key: 'CRAB',
symbol: 'xWCRAB',
address: '0x656567Eb75b765FC320783cc6EDd86bD854b2305',
outerAddress: '0x656567Eb75b765FC320783cc6EDd86bD854b2305',
protocolFee: 0,
decimals: 18,
}
],
channels: [
Expand All @@ -46,8 +42,8 @@ export class TransferService extends BaseTransferServiceT2 {
{
chainId: 44,
chain: 'crab-dvm',
url: this.crabUrl,
bridge: 'xtokenbridge',
url: this.darwainiaCrabIssuingUrl,
bridge: 'xtoken-darwinia-crab',
symbols: [
{
key: 'RING',
Expand All @@ -57,6 +53,42 @@ export class TransferService extends BaseTransferServiceT2 {
protocolFee: 0,
decimals: 18,
},
],
channels: [
{
chain: 'darwinia-dvm',
channel: 'msgport'
}
]
},
{
chainId: 46,
chain: 'darwinia-dvm',
url: this.crabDarwiniaIssuingUrl,
bridge: 'xtoken-crab-darwinia',
symbols: [
{
key: 'CRAB',
symbol: 'xWCRAB',
address: '0x656567Eb75b765FC320783cc6EDd86bD854b2305',
outerAddress: '0x656567Eb75b765FC320783cc6EDd86bD854b2305',
protocolFee: 0,
decimals: 18,
}
],
channels: [
{
chain: 'crab-dvm',
channel: 'msgport'
}
]
},
{
chainId: 44,
chain: 'crab-dvm',
url: this.crabDarwiniaBackingUrl,
bridge: 'xtoken-crab-darwinia',
symbols: [
{
key: 'CRAB',
symbol: 'CRAB',
Expand All @@ -72,15 +104,14 @@ export class TransferService extends BaseTransferServiceT2 {
channel: 'msgport'
}
]

}
];

testChainTransfers: PartnerT2[] = [
{
chainId: 43,
chain: 'pangolin-dvm',
url: this.darwainiaUrl,
url: this.darwiniaEthereumBackingUrl,
bridge: 'xtokenbridge',
symbols: [
{
Expand All @@ -102,7 +133,7 @@ export class TransferService extends BaseTransferServiceT2 {
{
chainId: 11155111,
chain: 'sepolia',
url: this.ethereumUrl,
url: this.darwiniaEthereumIssuingUrl,
bridge: 'xtokenbridge',
symbols: [
{
Expand Down
12 changes: 8 additions & 4 deletions apollo/src/xtoken/xtoken.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class xTokenService implements OnModuleInit {
chain.symbols.find(
(item) =>
item.key === symbolOrAddress ||
symbolOrAddress.toLowerCase() === item.address.toLowerCase()
symbolOrAddress?.toLowerCase() === item.address.toLowerCase()
) ?? null
);
}
Expand Down Expand Up @@ -123,23 +123,26 @@ export class xTokenService implements OnModuleInit {
})
.then((res) => res.data?.data?.transferRecords);

let added = 0;
if (records && records.length > 0) {
for (const record of records) {
const toChain = this.getDestChain(record.remoteChainId.toString(), transfer.bridge);
let sendTokenInfo, recvTokenInfo;

if (record.direction === 'lock') {
sendTokenInfo = this.getToken(transfer, record.token);
recvTokenInfo = this.getToken(toChain, sendTokenInfo.key);
recvTokenInfo = this.getToken(toChain, sendTokenInfo?.key);
} else {
recvTokenInfo = this.getToken(toChain, record.token);
sendTokenInfo = this.getToken(transfer, recvTokenInfo.key);
sendTokenInfo = this.getToken(transfer, recvTokenInfo?.key);
}

if (sendTokenInfo == null) {
latestNonce += 1;
continue;
}
if (recvTokenInfo == null) {
latestNonce += 1;
continue;
}

Expand Down Expand Up @@ -176,10 +179,11 @@ export class xTokenService implements OnModuleInit {
extData: record.extData,
});
latestNonce += 1;
added += 1;
}

this.logger.log(
`save new send record succeeded ${transfer.chain}, nonce: ${latestNonce}, added: ${records.length}`
`save new send record succeeded ${transfer.chain}, nonce: ${latestNonce}, added: ${added}/${records.length}`
);
this.fetchCache[index].latestNonce = latestNonce;
}
Expand Down
Loading

0 comments on commit cd9e7ac

Please sign in to comment.