-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added Liquidity helper function in
@buildwithsygma/utils
(#407)
When transferring fungible assets, its important to know whether liquidity is available on destination chain. Therefore, v3 SDK should provide interface to be able to query liquidity on destination chain and it should throw and error if there isn't enough liquidity. ## Implementation details - Interface for querying liquidity, fungible transfer passed as parameter - Destination provider should also be provided or created on demand by the SDK to query balances ## Testing details - Units tests for error and success cases ## Acceptance Criteria - A clean tested interface to query liquidity on destination chain for a specific 'transfer' object ## Closes #383
- Loading branch information
1 parent
abe928d
commit ad7b041
Showing
47 changed files
with
1,613 additions
and
891 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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import type { Config } from './config/config.js'; | ||
import type { Domainlike, EvmResource, Domain, SubstrateResource } from './types.js'; | ||
|
||
export interface BaseTransferParams { | ||
source: Domainlike; | ||
destination: Domainlike; | ||
resource: string | EvmResource | SubstrateResource; | ||
sourceAddress: string; | ||
} | ||
|
||
export abstract class BaseTransfer { | ||
protected destinationDomain: Domain; | ||
protected sourceDomain: Domain; | ||
protected transferResource: EvmResource | SubstrateResource; | ||
protected sygmaConfiguration: Config; | ||
|
||
protected sourceAddress: string; | ||
|
||
public get source(): Domain { | ||
return this.sourceDomain; | ||
} | ||
|
||
public get destination(): Domain { | ||
return this.destinationDomain; | ||
} | ||
|
||
public get resource(): EvmResource | SubstrateResource { | ||
return this.transferResource; | ||
} | ||
|
||
public get config(): Config { | ||
return this.sygmaConfiguration; | ||
} | ||
|
||
private findResource( | ||
resource: string | EvmResource | SubstrateResource, | ||
): EvmResource | SubstrateResource | undefined { | ||
return this.sygmaConfiguration.getResources(this.source).find(_resource => { | ||
return typeof resource === 'string' | ||
? resource === _resource.resourceId | ||
: resource.resourceId === _resource.resourceId; | ||
}); | ||
} | ||
|
||
protected constructor(transfer: BaseTransferParams, config: Config) { | ||
this.sygmaConfiguration = config; | ||
this.sourceAddress = transfer.sourceAddress; | ||
this.sourceDomain = config.getDomain(transfer.source); | ||
this.destinationDomain = config.getDomain(transfer.destination); | ||
const resource = this.findResource(transfer.resource); | ||
|
||
if (resource) { | ||
this.transferResource = resource; | ||
} else { | ||
throw new Error('Resource not found.'); | ||
} | ||
} | ||
/** | ||
* Method that checks whether the transfer | ||
* is valid and route has been registered on | ||
* the bridge | ||
* @returns {boolean} | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/require-await | ||
async isValidTransfer(): Promise<boolean> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
/** | ||
* Set resource to be transferred | ||
* @param {EvmResource} resource | ||
* @returns {BaseTransfer} | ||
*/ | ||
setResource(resource: EvmResource | SubstrateResource): void { | ||
this.transferResource = resource; | ||
} | ||
/** | ||
* | ||
* @param destination | ||
* @returns | ||
*/ | ||
setDesinationDomain(destination: Domainlike): void { | ||
const domain = this.config.getDomain(destination); | ||
this.destinationDomain = domain; | ||
} | ||
} |
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
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.